ListUtils<T> extension
Extension methods for Lists.
- on
-
- List<
T>
- List<
Methods
-
chunk(
int n) → List< List< T> > -
Available on List<
Split the list into chunks of sizeT> , provided by the ListUtils extensionn
. Returns a list of chunks. -
clearAndAddAll(
List< T> items) → void -
Available on List<
Clear and add all elements of ListT> , provided by the ListUtils extensionitems
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 -
Available on List<
Check if the list contains all elements of ListT> , provided by the ListUtils extensionitems
. Returnstrue
if the list contains all elements ofitems
,false
otherwise. -
distinctBy(
bool f(T)) → List< T> -
Available on List<
Distinct the list byT> , provided by the ListUtils extensionf
. Returns a new list with distinct elements based onf
. -
getFirst(
T item) → T? -
Available on List<
Get the first occurrence ofT> , provided by the ListUtils extensionitem
from the list. Returnsnull
if the item was not found. -
getLast(
T item) → T? -
Available on List<
Get the last occurrence ofT> , provided by the ListUtils extensionitem
from the list. Returnsnull
if the item was not found. -
groupBy<
K> (K f(T)) → Map< K, List< T> > -
Available on List<
Group the list byT> , provided by the ListUtils extensionf
. Returns a Map with the keys and values returned byf
. -
joinToString(
String separator, {String prefix = '', String suffix = '', String transform(T)?}) → String -
Available on List<
Join to String withT> , provided by the ListUtils extensionseparator
,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> -
Available on List<
Merge the list with ListT> , provided by the ListUtils extensionitems
. Returns a new list with all elements of the list anditems
. -
partition(
bool f(T)) → Pair< List< T> , List<T> > -
Available on List<
Split the list into two lists based onT> , provided by the ListUtils extensionf
. 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 -
Available on List<
Remove all occurrences ofT> , provided by the ListUtils extensionitem
from the list. -
removeAllIterable(
Iterable< T> items) → void -
Available on List<
Remove all occurrences of IterableT> , provided by the ListUtils extensionitems
from the list. -
removeAllList(
List< T> items) → void -
Available on List<
Remove all occurrences of ListT> , provided by the ListUtils extensionitems
from the list. -
removeAllMapKeys(
Map< T, dynamic> items) → void -
Available on List<
Remove all occurrences of MapT> , provided by the ListUtils extensionitems
keys from the list. -
removeAllMapValues(
Map< T, dynamic> items) → void -
Available on List<
Remove all occurrences of MapT> , provided by the ListUtils extensionitems
values from the list. -
removeAllSet(
Set< T> items) → void -
Available on List<
Remove all occurrences of SetT> , provided by the ListUtils extensionitems
from the list. -
removeFirst(
T item) → void -
Available on List<
Remove the first occurrence ofT> , provided by the ListUtils extensionitem
from the list. -
removeLast(
T item) → void -
Available on List<
Remove the last occurrence ofT> , provided by the ListUtils extensionitem
from the list. -
removeN(
T item, int n) → void -
Available on List<
Remove firstT> , provided by the ListUtils extensionn
occurrences ofitem
from the list. Ifn
is negative, remove from end of list. -
removeNList(
List< T> items, int n) → void -
Available on List<
Remove firstT> , provided by the ListUtils extensionn
occurrences of Listitems
from the list. Ifn
is negative, remove from end of list. -
sortedBy(
dynamic f(T)) → List< T> -
Available on List<
Sort the list byT> , provided by the ListUtils extensionf
. Returns a new list sorted byf
. -
sortedByDescending(
dynamic f(T)) → List< T> -
Available on List<
Returns a new list sorted byT> , provided by the ListUtils extensionf
descending. -
sumBy(
num f(T)) → num -
Available on List<
Sum byT> , provided by the ListUtils extensionf
of all elements in the list. Returns0
if the list is empty andf
returnsnull
. -
takeIf(
bool f(T)) → List< T> -
Available on List<
Take ifT> , provided by the ListUtils extensionf
is true. Returns a new list with the elements taken iff
is true. -
takeWhile(
bool f(T)) → List< T> -
Available on List<
Take whileT> , provided by the ListUtils extensionf
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> -
Available on List<
Convert the list to a Map withT> , provided by the ListUtils extensionkey
andvalue
functions. Returns a new Map with the keys and values returned bykey
andvalue
.