IterableExtensions<T> extension

Extension methods on Iterable providing collection operations commonly found in other languages but absent from the Dart SDK.

final items = [1, 2, 3, 4, 5];
print(items.chunked(2));          // [[1, 2], [3, 4], [5]]
print(items.windowed(3));         // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
print(items.intersperse(0));      // [1, 0, 2, 0, 3, 0, 4, 0, 5]
on

Methods

associate<K, V>(MapEntry<K, V> transform(T)) Map<K, V>

Available on Iterable<T>, provided by the IterableExtensions extension

Associates each element of this iterable into a Map by applying transform to produce a MapEntry.
chunked(int size) Iterable<List<T>>

Available on Iterable<T>, provided by the IterableExtensions extension

Splits this iterable into chunks of size.
distinctBy<K>(K key(T)) Iterable<T>

Available on Iterable<T>, provided by the IterableExtensions extension

Returns a new iterable containing only elements that are distinct by the value returned by key.
firstWhereOrNull(bool test(T)) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

Returns the first element that satisfies test, or null if none does.
intersperse(T separator) Iterable<T>

Available on Iterable<T>, provided by the IterableExtensions extension

Returns an iterable with separator inserted between each pair of consecutive elements.
partition(bool test(T)) → (List<T>, List<T>)

Available on Iterable<T>, provided by the IterableExtensions extension

Partitions this iterable into two lists: elements that satisfy test and those that do not.
singleWhereOrNull(bool test(T)) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

Returns the single element that satisfies test, or null if none does.
windowed(int size) Iterable<List<T>>

Available on Iterable<T>, provided by the IterableExtensions extension

Returns a sliding window view of size over this iterable.
zip(Iterable other) Iterable<List>

Available on Iterable<T>, provided by the IterableExtensions extension

Zips this iterable with other into an iterable of Lists of length 2.