IterableExtensions<E> extension
A collection of helpful extensions on Iterable to reduce boilerplate.
- on
-
- Iterable<
E>
- Iterable<
Methods
-
chunk(
int size) → List< List< E> > -
Available on Iterable<
Splits the iterable into chunks of the givenE> , provided by the IterableExtensions extensionsize. Example:[1, 2, 3, 4, 5].chunk(2)->[[1, 2], [3, 4], [5]] -
groupBy<
K> (K keyFunction(E)) → Map< K, List< E> > -
Available on Iterable<
Groups the elements in the iterable by a key returned byE> , provided by the IterableExtensions extensionkeyFunction. Example:users.groupBy((u) => u.role) -
random(
) → E? -
Available on Iterable<
Returns a random element from the iterable. Returns null if the iterable is empty. Example:E> , provided by the IterableExtensions extension[1, 2, 3].random() -
sorted(
[int compare(E a, E b)?]) → List< E> -
Available on Iterable<
Returns a new sorted list from the iterable. Example:E> , provided by the IterableExtensions extension[3, 1, 2].sorted()->[1, 2, 3] -
unique(
[dynamic id(E)?]) → List< E> -
Available on Iterable<
Returns a list containing only unique elements. IfE> , provided by the IterableExtensions extensionidis provided, uniqueness is determined by the returned identifier. Example:[1, 1, 2].unique()->[1, 2]