ListExtension<E> extension

Provides convenient List extensions

on

Methods

addAllIfNotNull(List<E>? items) → void

Available on List<E>, provided by the ListExtension extension

Adds all items from items to the list if items is not null or empty.
addIfNotNull(E? item) → void

Available on List<E>, provided by the ListExtension extension

Adds item to the list if item is not null.
all(bool test(E e)) bool

Available on List<E>, provided by the ListExtension extension

Returns true if all elements in the list satisfy the given test.
any(bool test(E e)) bool

Available on List<E>, provided by the ListExtension extension

Returns true if any element in the list satisfies the given test.
chunk(int chunkSize) List<List<E>>

Available on List<E>, provided by the ListExtension extension

Returns a new list containing chunks of the original list with the specified chunkSize.
evenList() List<E>

Available on List<E>, provided by the ListExtension extension

Returns a new list containing elements at even indices.
oddList() List<E>

Available on List<E>, provided by the ListExtension extension

Returns a new list containing elements at odd indices.
randomElement() → E?

Available on List<E>, provided by the ListExtension extension

Safely returns a random element from the list. Returns null if the list is empty.
safeGet(int index) → E?

Available on List<E>, provided by the ListExtension extension

Safely returns the element at the given index. Returns null if the index is out of bounds.
skipFrom(int start) List<E>

Available on List<E>, provided by the ListExtension extension

Returns a new list containing elements from this list starting from start.
swap(int index1, int index2) → void

Available on List<E>, provided by the ListExtension extension

Swaps the elements at index1 and index2. Throws a RangeError if indices are out of bounds.
takeUpTo(int end) List<E>

Available on List<E>, provided by the ListExtension extension

Returns a new list containing elements from this list up to, but not including, end.
to<T>(T generator(E e)) List<T>

Available on List<E>, provided by the ListExtension extension

Maps each element of this list to a new value and returns a new list. This is equivalent to map(generator).toList().
whereToList(bool test(E e)) List<E>

Available on List<E>, provided by the ListExtension extension

Returns a new list containing elements that satisfy the given test.