ListUtils<T> extension

Extension methods for Lists.

on

Methods

chunk(int n) List<List<T>>

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

Split the list into chunks of size n. Returns a list of chunks.
clearAndAddAll(List<T> items) → void

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

Clear and add all elements of List items to the list.
compact() List<T>

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

Remove null or empty elements from the list. Returns a new list with null or empty elements removed.
containsAllList(List<T> items) bool

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

Check if the list contains all elements of List items. Returns true if the list contains all elements of items, false otherwise.
distinctBy(bool f(T)) List<T>

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

Distinct the list by f. Returns a new list with distinct elements based on f.
getFirst(T item) → T?

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

Get the first occurrence of item from the list. Returns null if the item was not found.
getLast(T item) → T?

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

Get the last occurrence of item from the list. Returns null if the item was not found.
groupBy<K>(K f(T)) Map<K, List<T>>

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

Group the list by f. Returns a Map with the keys and values returned by f.
joinToString(String separator, {String prefix = '', String suffix = '', String transform(T)?}) String

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

Join to String with separator, prefix and suffix, and transform function. Returns a String with the elements joined by separator, prefix and suffix, and transformed by transform. If transform is null, the elements are converted to String with toString().
mergeList(List<T> items, {bool unique = false}) List<T>

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

Merge the list with List items. Returns a new list with all elements of the list and items.
partition(bool f(T)) Pair<List<T>, List<T>>

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

Split the list into two lists based on f. Returns a list of two lists of T. The first list contains all elements for which f returns true. The second list contains all elements for which f returns false.
removeAll(T item) → void

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

Remove all occurrences of item from the list.
removeAllIterable(Iterable<T> items) → void

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

Remove all occurrences of Iterable items from the list.
removeAllList(List<T> items) → void

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

Remove all occurrences of List items from the list.
removeAllMapKeys(Map<T, dynamic> items) → void

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

Remove all occurrences of Map items keys from the list.
removeAllMapValues(Map<T, dynamic> items) → void

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

Remove all occurrences of Map items values from the list.
removeAllSet(Set<T> items) → void

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

Remove all occurrences of Set items from the list.
removeFirst(T item) → void

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

Remove the first occurrence of item from the list.
removeLast(T item) → void

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

Remove the last occurrence of item from the list.
removeN(T item, int n) → void

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

Remove first n occurrences of item from the list. If n is negative, remove from end of list.
removeNList(List<T> items, int n) → void

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

Remove first n occurrences of List items from the list. If n is negative, remove from end of list.
sortedBy(dynamic f(T)) List<T>

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

Sort the list by f. Returns a new list sorted by f.
sortedByDescending(dynamic f(T)) List<T>

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

Returns a new list sorted by f descending.
sumBy(num f(T)) num

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

Sum by f of all elements in the list. Returns 0 if the list is empty and f returns null.
takeIf(bool f(T)) List<T>

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

Take if f is true. Returns a new list with the elements taken if f is true.
takeWhile(bool f(T)) List<T>

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

Take while f is true. Returns a new list with the elements taken while f is true.
toMap<K, V>(K key(T), V value(T)) Map<K, V>

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

Convert the list to a Map with key and value functions. Returns a new Map with the keys and values returned by key and value.