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
-
- Iterable<
T>
- Iterable<
- Available Extensions
Constructors
-
NonEmptyList(List<
T> items) - Constructs a NonEmptyList.
Properties
- first → T
-
Gets the first element in the list.
read-onlyoverride
- hashCode → int
-
The hash code for this object.
read-onlyinherited
- isEmpty → bool
-
Returns true if there are no elements in this collection.
read-onlyoverride
- isNotEmpty → bool
-
Returns true if there is at least one element in this collection.
read-onlyoverride
-
items
→ UnmodifiableListView<
T> -
Provides an unmodifiable view of the items.
read-only
-
iterator
→ Iterator<
T> -
A new
Iterator
that allows iterating the elements of thisIterable
.read-onlyoverride - last → T
-
Gets the last element in the list.
read-onlyoverride
- length → int
-
Gets the number of elements in this list.
read-onlyoverride
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
- single → T
-
Gets the single element in the list. Throws an error if the list has more
than one item.
read-onlyoverride
Methods
-
any(
bool test(T)) → bool -
Checks if any item in the list satisfies the provided test.
override
-
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
-
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 theorElse
function if provided.override -
fold<
T0> (T0 initialValue, T0 combine(T0, T)) → T0 -
Accumulates value starting with
initialValue
and applyingcombine
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 theorElse
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 typeT0
.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 theorElse
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< T0> -
Returns a new lazy Iterable with all elements that have type
T0
.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited