ListExtensions<T> extension

Common list extensions

on

Properties

isEmptyOrNull bool

Available on List<T>, provided by the ListExtensions extension

Checks if the list is empty or only contains null values.
no setter
random → T?

Available on List<T>, provided by the ListExtensions extension

Randomly gets an element from the list. Returns null if the list is empty.
no setter
reversedList List<T>

Available on List<T>, provided by the ListExtensions extension

Returns a new list with the elements in reverse order.
no setter
shuffled List<T>

Available on List<T>, provided by the ListExtensions extension

Shuffles the elements of the list into a random order.
no setter
unique List<T>

Available on List<T>, provided by the ListExtensions extension

Returns a new list containing only the unique elements from the original list.
no setter

Methods

addIfNotContains(T element) → void

Available on List<T>, provided by the ListExtensions extension

Adds an element to the list if it does not already contain it.
chunked(int chunkSize) List<List<T>>

Available on List<T>, provided by the ListExtensions extension

Creates subLists of a given size from the list.
firstWhereOrElse(bool test(T), T orElse) → T

Available on List<T>, provided by the ListExtensions extension

Finds the first element matching test, or returns orElse if none match.
firstWhereOrNull(bool test(T)) → T?

Available on List<T>, provided by the ListExtensions extension

Tries to find the first element in the list that matches the given test. Returns null if no such element is found.
groupBy<K>(K keyFunction(T)) Map<K, List<T>>

Available on List<T>, provided by the ListExtensions extension

Groups the elements in the list according to the keyFunction. Returns a map where each key corresponds to a list of elements that share that key.
mapToList<E>(E convert(T)) List<E>

Available on List<T>, provided by the ListExtensions extension

Converts each element in the list to another type using the convert function. Returns a new list containing the converted elements.
removeFirstWhere(bool test(T)) bool

Available on List<T>, provided by the ListExtensions extension

Removes the first element in the list that satisfies the given test. Returns true if an element was removed, otherwise false.
safeElementAt([int? index]) → T?

Available on List<T>, provided by the ListExtensions extension

Safely gets an element from the list at the given index. Returns null if the index is out of bounds.