ListUtils<T> extension
Extension methods for Lists.
- on
-
- List<
T>
- List<
Methods
-
chunk(
int n) → List< List< T> > -
Split the list into chunks of size
n
. Returns a list of chunks. -
clearAndAddAll(
List< T> items) → void -
Clear and add all elements of List
items
to the list. -
compact(
) → List< T> - Remove null or empty elements from the list. Returns a new list with null or empty elements removed.
-
containsAllList(
List< T> items) → bool -
Check if the list contains all elements of List
items
. Returnstrue
if the list contains all elements ofitems
,false
otherwise. -
distinctBy(
dynamic f(T)) → List< T> -
Distinct the list by
f
. Returns a new list with distinct elements based onf
. -
getFirst(
T item) → T? -
Get the first occurrence of
item
from the list. Returnsnull
if the item was not found. -
getLast(
T item) → T? -
Get the last occurrence of
item
from the list. Returnsnull
if the item was not found. -
groupBy<
K> (K f(T)) → Map< K, List< T> > -
Group the list by
f
. Returns a Map with the keys and values returned byf
. -
joinToString(
String separator, {String prefix = '', String suffix = '', String transform(T)?}) → String -
Join to String with
separator
,prefix
andsuffix
, andtransform
function. Returns a String with the elements joined byseparator
,prefix
andsuffix
, and transformed bytransform
. Iftransform
isnull
, the elements are converted to String withtoString()
. -
mergeList(
List< T> items, {bool unique = false}) → List<T> -
Merge the list with List
items
. Returns a new list with all elements of the list anditems
. -
partition(
bool f(T)) → Pair< List< T> , List<T> > -
Split the list into two lists based on
f
. Returns a list of two lists ofT
. The first list contains all elements for whichf
returnstrue
. The second list contains all elements for whichf
returnsfalse
. -
removeAll(
T item) → void -
Remove all occurrences of
item
from the list. -
removeAllIterable(
Iterable< T> items) → void -
Remove all occurrences of Iterable
items
from the list. -
removeAllList(
List< T> items) → void -
Remove all occurrences of List
items
from the list. -
removeAllMapKeys(
Map< T, dynamic> items) → void -
Remove all occurrences of Map
items
keys from the list. -
removeAllMapValues(
Map< T, dynamic> items) → void -
Remove all occurrences of Map
items
values from the list. -
removeAllSet(
Set< T> items) → void -
Remove all occurrences of Set
items
from the list. -
removeFirst(
T item) → void -
Remove the first occurrence of
item
from the list. -
removeLast(
T item) → void -
Remove the last occurrence of
item
from the list. -
removeN(
T item, int n) → void -
Remove first
n
occurrences ofitem
from the list. Ifn
is negative, remove from end of list. -
removeNList(
List< T> items, int n) → void -
Remove first
n
occurrences of Listitems
from the list. Ifn
is negative, remove from end of list. -
sortedBy(
dynamic f(T)) → List< T> -
Sort the list by
f
. Returns a new list sorted byf
. -
sortedByDescending(
dynamic f(T)) → List< T> -
Returns a new list sorted by
f
descending. -
sumBy(
num f(T)) → num -
Sum by
f
of all elements in the list. Returns0
if the list is empty andf
returnsnull
. -
takeIf(
bool f(T)) → List< T> -
Take if
f
is true. Returns a new list with the elements taken iff
is true. -
takeWhile(
bool f(T)) → List< T> -
Take while
f
is true. Returns a new list with the elements taken whilef
is true. -
toMap<
K, V> (K key(T), V value(T)) → Map< K, V> -
Convert the list to a Map with
key
andvalue
functions. Returns a new Map with the keys and values returned bykey
andvalue
.