UniqueList<E>.unmodifiable constructor

UniqueList<E>.unmodifiable(
  1. Iterable<E> elements, {
  2. bool nullable = true,
})

Creates an unmodifiable list containing all elements.

The Iterator of elements provides the order of the elements.

An unmodifiable list cannot have its length or elements changed. If the elements are themselves immutable, then the resulting list is also immutable.

If nullable is true, the list may contain multiple instances of null, otherwise, null will be treated like any other value and only one instance of null may be contained in the list.

Implementation

factory UniqueList.unmodifiable(
  Iterable<E> elements, {
  bool nullable = true,
}) {
  final list = List<E>.unmodifiable(elements);

  if (_containsDuplicateValues(list, nullable: nullable)) {
    throw DuplicateValuesError(
        UniqueList._getDuplicateValue<E>(list, nullable: nullable));
  }

  return UniqueList<E>._(list, nullable: nullable, growable: false);
}