ListExtensions<T> extension
Common list extensions
- on
-
- List<
T>
- List<
Properties
- isEmptyOrNull → bool
-
Available on List<
Checks if the list is empty or only contains null values.T> , provided by the ListExtensions extensionno setter - random → T?
-
Available on List<
Randomly gets an element from the list. Returns null if the list is empty.T> , provided by the ListExtensions extensionno setter -
reversedList
→ List<
T> -
Available on List<
Returns a new list with the elements in reverse order.T> , provided by the ListExtensions extensionno setter -
shuffled
→ List<
T> -
Available on List<
Shuffles the elements of the list into a random order.T> , provided by the ListExtensions extensionno setter -
unique
→ List<
T> -
Available on List<
Returns a new list containing only the unique elements from the original list.T> , provided by the ListExtensions extensionno setter
Methods
-
addIfNotContains(
T element) → void -
Available on List<
Adds an element to the list if it does not already contain it.T> , provided by the ListExtensions extension -
chunked(
int chunkSize) → List< List< T> > -
Available on List<
Creates subLists of a given size from the list.T> , provided by the ListExtensions extension -
firstWhereOrElse(
bool test(T), T orElse) → T -
Available on List<
Finds the first element matchingT> , provided by the ListExtensions extensiontest, or returnsorElseif none match. -
firstWhereOrNull(
bool test(T)) → T? -
Available on List<
Tries to find the first element in the list that matches the givenT> , provided by the ListExtensions extensiontest. Returns null if no such element is found. -
groupBy<
K> (K keyFunction(T)) → Map< K, List< T> > -
Available on List<
Groups the elements in the list according to theT> , provided by the ListExtensions extensionkeyFunction. 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<
Converts each element in the list to another type using theT> , provided by the ListExtensions extensionconvertfunction. Returns a new list containing the converted elements. -
removeFirstWhere(
bool test(T)) → bool -
Available on List<
Removes the first element in the list that satisfies the givenT> , provided by the ListExtensions extensiontest. Returns true if an element was removed, otherwise false. -
safeElementAt(
[int? index]) → T? -
Available on List<
Safely gets an element from the list at the givenT> , provided by the ListExtensions extensionindex. Returns null if theindexis out of bounds.