NonEmptyList<T> class

A list that is guaranteed to have at least one item.

This is a wrapper around a standard Dart list that ensures it's never empty. It also provides an unmodifiable view to ensure that no empty lists are set.

Example:

final myList = NonEmptyList([1, 2, 3]);
print(myList.first); // prints 1
Implemented types
Available extensions

Constructors

NonEmptyList(List<T> items)
Constructs a NonEmptyList.

Properties

first → T
Gets the first element in the list.
no setteroverride
firstOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The first element of this iterator, or null if the iterable is empty.
no setter
hashCode → int
The hash code for this object.
no setterinherited
indexed → Iterable<(int, T)>

Available on Iterable<T>, provided by the IterableExtensions extension

Pairs of elements of the indices and elements of this iterable.
no setter
isEmpty → bool
Returns true if there are no elements in this collection.
no setteroverride
isNotEmpty → bool
Returns true if there is at least one element in this collection.
no setteroverride
items → UnmodifiableListView<T>
Provides an unmodifiable view of the items.
no setter
iterator → Iterator<T>
A new Iterator that allows iterating the elements of this Iterable.
no setteroverride
last → T
Gets the last element in the list.
no setteroverride
lastOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The last element of this iterable, or null if the iterable is empty.
no setter
length → int
Gets the number of elements in this list.
no setteroverride
nonNulls → Iterable<T>

Available on Iterable<T?>, provided by the NullableIterableExtensions extension

The non-null elements of this iterable.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
single → T
Gets the single element in the list. Throws an error if the list has more than one item.
no setteroverride
singleOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The single element of this iterator, or null.
no setter
toJSIterable → JSIterable<T>

Available on Iterable<T>, provided by the IterableToJSIterable extension

A JSIterable wrapper that proxies to the Dart iterable API.
no setter
wait → Future<List<T>>

Available on Iterable<Future<T>>, provided by the FutureIterable extension

Waits for futures in parallel.
no setter

Methods

any(bool test(T)) → bool
Checks if any item in the list satisfies the provided test.
override
asNameMap() → Map<String, T>

Available on Iterable<T>, provided by the EnumByName extension

Creates a map from the names of enum values to the values.
byName(String name) → T

Available on Iterable<T>, provided by the EnumByName extension

Finds the enum value in this list with name name.
cast<R>() → Iterable<R>
Casts the items of the list to the desired type R.
override
contains(Object? element) → bool
Determines if the list contains the provided element.
override
elementAt(int index) → T
Returns the element at the specified index.
override
elementAtOrNull(int index) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The element at position index of this iterable, or null.
every(bool test(T)) → bool
Checks if every item in the list satisfies the provided test.
override
expand<T0>(Iterable<T0> f(T)) → Iterable<T0>
Expands each element into zero or more elements.
override
firstWhere(bool test(T), {T orElse()?}) → T
Gets the first element that satisfies the given predicate test. If none are found, it calls the orElse function if provided.
override
fold<T0>(T0 initialValue, T0 combine(T0, T)) → T0
Accumulates value starting with initialValue and applying combine for each element in order.
override
followedBy(Iterable<T> other) → Iterable<T>
Appends all elements of other to the end of this iterable's elements.
override
forEach(void f(T)) → void
Applies the function f to each element of this collection.
override
join([String separator = ""]) → String
Converts the items in the list to a string and concatenates them using the provided separator.
override
lastWhere(bool test(T), {T orElse()?}) → T
Gets the last element that satisfies the given predicate test. If none are found, it calls the orElse function if provided.
override
map<T0>(T0 f(T)) → Iterable<T0>
Applies the function f to each element in the list and returns a new iterable with elements of type T0.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(T combine(T, T)) → T
Reduces the elements in the list to a single value using the combine function.
override
singleWhere(bool test(T), {T orElse()?}) → T
Gets the single element that satisfies the given predicate test. If none are found, it calls the orElse function if provided.
override
skip(int count) → Iterable<T>
Skips the first count elements.
override
skipWhile(bool test(T)) → Iterable<T>
Skips leading elements while they satisfy test.
override
take(int count) → Iterable<T>
Returns the first count elements.
override
takeWhile(bool test(T)) → Iterable<T>
Returns leading elements satisfying test.
override
toList({bool growable = true}) → List<T>
Returns a list representation of the iterable.
override
toSet() → Set<T>
Returns a set containing the same elements as this iterable.
override
toString() → String
A string representation of this object.
override
where(bool test(T)) → Iterable<T>
Returns a new lazy Iterable with all elements that satisfy the predicate test.
override
whereType<T0>() → Iterable<R>
Returns a new lazy Iterable with all elements that have type T0.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited