ListUtils<T> extension
Extensions on List for real-world utility operations.
- on
-
- List<
T>
- List<
Properties
- average → double
-
Available on List<
Returns the average of aT> , provided by the ListUtils extensionList<num>. Returns0if empty.no setter - lastOrNull → T?
-
Available on List<
Returns the last element, orT> , provided by the ListUtils extensionnullif the list is empty.no setter - median → double
-
Available on List<
Returns the median of aT> , provided by the ListUtils extensionList<num>. Returns0if empty.no setter - mode → T?
-
Available on List<
Returns the most frequently occurring element, orT> , provided by the ListUtils extensionnullif empty.no setter - penultimate → T?
-
Available on List<
Returns the second-to-last element, orT> , provided by the ListUtils extensionnullif the list has fewer than 2 items.no setter - second → T?
-
Available on List<
Returns the second element, orT> , provided by the ListUtils extensionnullif the list has fewer than 2 items.no setter - third → T?
-
Available on List<
Returns the third element, orT> , provided by the ListUtils extensionnullif the list has fewer than 3 items.no setter
Methods
-
averageBy(
num f(T)) → double -
Available on List<
Returns the average of the list by applyingT> , provided by the ListUtils extensionfto each element. Returns0if the list is empty. -
chunk(
int size) → List< List< T> > -
Available on List<
Splits the list into chunks ofT> , provided by the ListUtils extensionsize. -
clearAndAddAll(
List< T> items) → void -
Available on List<
Clears this list and adds all elements fromT> , provided by the ListUtils extensionitems. -
compact(
) → List< T> - Removes null and empty (String/Iterable/Map) elements.
-
containsAllList(
List< T> items) → bool -
Available on List<
ReturnsT> , provided by the ListUtils extensiontrueif this list contains all elements ofitems. -
cumulativeSum(
) → List< num> -
Available on List<
Returns the running cumulative sum of aT> , provided by the ListUtils extensionList<num>. -
difference(
List< T> other) → List<T> -
Available on List<
Returns elements in this list that are NOT inT> , provided by the ListUtils extensionother. -
distinct(
) → List< T> - Returns a new list with duplicate elements removed (preserves order).
-
distinctBy<
K> (K key(T)) → List< T> -
Available on List<
Returns a new list with distinct elements based onT> , provided by the ListUtils extensionkey. -
firstWhereOrNull(
bool predicate(T)) → T? -
Available on List<
Returns the first element satisfyingT> , provided by the ListUtils extensionpredicate, ornullif none found. -
flatten<
R> () → List< R> -
Available on List<
Flattens aT> , provided by the ListUtils extensionList<List<R>>into aList<R>. -
frequencies(
) → Map< T, int> - Returns a map of each element to its occurrence count.
-
groupBy<
K> (K key(T)) → Map< K, List< T> > -
Available on List<
Groups elements byT> , provided by the ListUtils extensionkey, returning aMap<K, List<T>>. -
insertAt(
int index, T item) → void -
Available on List<
InsertsT> , provided by the ListUtils extensionitematindex, clamped to valid range. -
intersection(
List< T> other) → List<T> -
Available on List<
Returns elements that appear in both this list andT> , provided by the ListUtils extensionother. -
intersperse(
T separator) → List< T> -
Available on List<
Returns a new list withT> , provided by the ListUtils extensionseparatorinserted between every element. -
joinToString(
String separator, {String prefix = '', String suffix = '', String transform(T)?}) → String -
Available on List<
Joins elements to a string withT> , provided by the ListUtils extensionseparator, optionalprefix/suffix, and optionaltransform. -
mergeList(
List< T> other, {bool unique = false}) → List<T> -
Available on List<
Merges this list withT> , provided by the ListUtils extensionother. Ifuniqueistrue, duplicates are excluded. -
move(
int from, int to) → void -
Available on List<
Moves the element atT> , provided by the ListUtils extensionfromtoto, shifting other elements. -
page(
int page, int pageSize) → List< T> - Returns a page of elements (1-indexed).
-
partition(
bool predicate(T)) → Pair< List< T> , List<T> > -
Available on List<
Splits the list into a Pair based onT> , provided by the ListUtils extensionpredicate. First list: elements where predicate istrue. Second list: elements where predicate isfalse. -
random(
{int? seed}) → T -
Available on List<
Returns a random element from the list. Throws StateError if the list is empty.T> , provided by the ListUtils extension -
removeAll(
T item) → void -
Available on List<
Removes all occurrences ofT> , provided by the ListUtils extensionitemfrom the list. -
removeFirst(
T item) → void -
Available on List<
Removes the first occurrence ofT> , provided by the ListUtils extensionitemfrom the list. -
removeLastOccurrence(
T item) → void -
Available on List<
Removes the last occurrence ofT> , provided by the ListUtils extensionitemfrom the list. -
removeN(
T item, int n) → void -
Available on List<
Removes the firstT> , provided by the ListUtils extensionnoccurrences ofitem(or last ifnis negative). -
rotate(
int n) → List< T> -
Available on List<
Rotates the list left byT> , provided by the ListUtils extensionnpositions (negative = right rotation). -
sample(
int n, {int? seed}) → List< T> -
Available on List<
ReturnsT> , provided by the ListUtils extensionnrandom elements without replacement. -
sortedBy<
K extends Comparable> (K key(T)) → List< T> -
Available on List<
Returns a new list sorted ascending byT> , provided by the ListUtils extensionkey. -
sortedByDescending<
K extends Comparable> (K key(T)) → List< T> -
Available on List<
Returns a new list sorted descending byT> , provided by the ListUtils extensionkey. -
sumBy(
num f(T)) → num -
Available on List<
Sums the list by applyingT> , provided by the ListUtils extensionfto each element. -
swap(
int i, int j) → void -
Available on List<
Swaps elements at indicesT> , provided by the ListUtils extensioniandjin place. -
toMap<
K, V> (K key(T), V value(T)) → Map< K, V> -
Available on List<
Converts this list to aT> , provided by the ListUtils extensionMap<K, V>usingkeyandvalueselectors. -
toPairs(
) → List< Pair< T, T> > - Returns consecutive pairs of elements.
-
transpose(
) → List< List< T> > -
Available on List<
Transposes aT> , provided by the ListUtils extensionList<List<T>>(rows become columns). -
windowed(
int size, {int step = 1}) → List< List< T> > -
Available on List<
Returns a sliding window ofT> , provided by the ListUtils extensionsizeover the list. -
zip<
U> (List< U> other) → List<Pair< T, U> > -
Available on List<
Zips this list withT> , provided by the ListUtils extensionotherinto a list of Pairs. Stops at the shorter list.