Arr class
Static utility methods for working with lists.
Arr.wrap('foo'); // ['foo']
Arr.flatten([1, [2, [3]]]); // [1, 2, 3]
Arr.chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
Arr.pluck(users, 'name'); // ['Anna', 'Brad']
Arr.keyBy(users, 'id'); // {1: {...}, 2: {...}}
Available helpers:
Type checks:
Construction:
Filtering:
Slicing / chunking:
- take, chunk, prepend, push, interleave
Ordering:
Random:
Iteration:
Mutations (immutable):
Aggregates:
Map-list operations:
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
accessible(
Object? value) → bool -
Returns true when
valueis aListorMap(i.e. index/key accessible). -
average<
T> (Iterable< T> list, {num by(T)?}) → double -
Returns the arithmetic mean of
list, or0when empty. -
chunk<
T> (Iterable< T> list, int size) → List<List< T> > -
Splits
listinto chunks ofsizeelements. -
collapse<
T> (Iterable< Iterable< arrays) → List<T> >T> - Collapses a list of lists into a single list.
-
countBy<
T, K> (Iterable< T> list, {K by(T)?}) → Map<K, int> -
Counts occurrences in
list, optionally grouping by the value ofby. -
crossJoin(
Iterable< Iterable> lists) → List<List> -
Cross joins the given
lists, returning every possible combination. -
every<
T> (Iterable< T> list, bool predicate(T)) → bool -
Returns true when every element of
listpassespredicate. Vacuously true for empty lists. -
exceptValues<
T> (Iterable< T> list, Iterable<T> values) → List<T> -
Returns
listwith each ofvaluesremoved. -
first<
T> (Iterable< T> list, {bool predicate(T)?, T? defaultValue}) → T? -
Returns the first element matching
predicate, ordefaultValue. -
flatMap<
T, R> (Iterable< T> list, Iterable<R> fn(T)) → List<R> -
Maps each element of
listthroughfn, flattening the resulting iterables into a single list. -
flatten(
Iterable list, {int depth = -1}) → List - Flattens a nested iterable into a single-level list.
-
groupBy<
T, K> (Iterable< T> list, K by(T)) → Map<K, List< T> > -
Groups
listinto a map keyed by the value returned byby. -
indexed<
T> (Iterable< T> list) → List<(int, T)> -
Pairs each element of
listwith its index, returning a list of(index, value)records. -
interleave<
T> (Iterable< T> list, T separator) → List<T> -
Returns
listwithseparatorinserted between every pair of elements. -
isAssoc(
Object? value) → bool -
Returns true when
valueis aMap(associative). -
isList(
Object? value) → bool -
Returns true when
valueis aList. -
join(
Iterable list, [String separator = ', ', String finalSeparator = '']) → String -
Joins
listinto a string withseparator; the final element is joined withfinalSeparatorwhen provided. -
keyBy<
K, V> (Iterable< Map< list, K key) → Map<K, V> >V, Map< K, V> > -
Indexes
listby the value atkey. Entries with anullvalue atkeyare skipped. -
last<
T> (Iterable< T> list, {bool predicate(T)?, T? defaultValue}) → T? -
Returns the last element matching
predicate, ordefaultValue. -
map<
T, R> (Iterable< T> list, R callback(T value, int index)) → List<R> -
Maps each element of
listthroughcallback, passing the index too. -
mapWithKeys<
T, K, V> (Iterable< T> list, MapEntry<K, V> callback(T)) → Map<K, V> -
Maps each element of
listto aMapEntry, returning the resulting map. -
max<
T> (Iterable< T> list, {Comparable by(T)?}) → T -
Returns the element of
listwith the largest value ofby(or the largest element itself whenbyis null andTisComparable). -
median<
T> (Iterable< T> list, {num by(T)?}) → double -
Returns the median of
list, or0when empty. -
min<
T> (Iterable< T> list, {Comparable by(T)?}) → T -
Returns the element of
listwith the smallest value ofby(or the smallest element itself whenbyis null andTisComparable). -
move<
T> (Iterable< T> list, int from, int to) → List<T> -
Returns a new list with the element at
frommoved to positionto. -
onlyValues<
T> (Iterable< T> list, Iterable<T> values) → List<T> -
Returns the elements of
listthat are also invalues. -
partition<
T> (Iterable< T> list, bool predicate(T)) → List<List< T> > -
Splits
listinto a[matching, nonMatching]pair based onpredicate. -
pluck<
K, V> (Iterable< Map< list, K key) → List<K, V> >V?> -
Plucks the value at
keyfrom each map inlist. -
prepend<
T> (Iterable< T> list, T value) → List<T> -
Returns a new list with
valueinserted at the front. -
push<
T> (Iterable< T> list, T value) → List<T> -
Returns a new list with
valueappended at the end. -
random<
T> (List< T> list) → T -
Returns a random element of
list. Throws whenlistis empty. -
randomMany<
T> (List< T> list, int count) → List<T> -
Returns up to
countrandom elements oflistwithout replacement. -
reject<
T> (Iterable< T> list, bool predicate(T)) → List<T> -
Filters
listto elements NOT matchingpredicate. Inverse of where. -
replaceAt<
T> (Iterable< T> list, int index, T value) → List<T> -
Returns a new list with the element at
indexreplaced byvalue. Throws RangeError whenindexis out of range. -
select<
K, V> (Iterable< Map< list, Iterable<K, V> >K> keys) → List<Map< K, V> > -
Returns each map in
listreduced to only the givenkeys. -
shuffle<
T> (Iterable< T> list, {int? seed}) → List<T> -
Returns a shuffled copy of
list. Passseedfor determinism. -
sole<
T> (Iterable< T> list, {bool predicate(T)?}) → T -
Returns the single element matching
predicate. Throws if zero or more than one element matches. -
some<
T> (Iterable< T> list, bool predicate(T)) → bool -
Returns true when at least one element of
listpassespredicate. -
sort<
T> (Iterable< T> list, {int compare(T, T)?}) → List<T> -
Returns a sorted copy of
list. -
sortDesc<
T extends Comparable> (Iterable< T> list) → List<T> -
Returns a sorted copy of
listin descending order. -
sortRecursive(
List list, {int compare(dynamic, dynamic)?}) → List -
Recursively sorts
list. Nested lists are sorted at every depth; values of mixed types fall back to string comparison. -
sum<
T> (Iterable< T> list, {num by(T)?}) → num -
Returns the sum of
list. Passbyto extract a number from each element; otherwiselistmust beIterable<num>. -
swap<
T> (Iterable< T> list, int i, int j) → List<T> -
Returns a new list with the elements at
iandjswapped. -
take<
T> (Iterable< T> list, int count) → List<T> -
Returns the first
countelements oflist, or lastcountif negative. -
unique<
T> (Iterable< T> list) → List<T> -
Returns the unique values of
list. -
where<
T> (Iterable< T> list, bool predicate(T)) → List<T> -
Filters
listto elements matchingpredicate. -
whereNotNull<
T> (Iterable< T?> list) → List<T> -
Returns
listwithnullvalues removed. -
wrap(
Object? value) → List -
Wraps
valuein aListif it isn't already one. Returns an empty list when value isnull.