Kotlin Collection Ops

19 functions

filtercollection.filter { predicate }

Returns a collection containing only elements matching the given predicate.

mapcollection.map { transform }

Returns a list containing the results of applying the given transform function.

flatMapcollection.flatMap { transform }

Returns a single list of all elements from results of transform applied to each element.

reducecollection.reduce { acc, e -> }

Accumulates value starting with the first element and applying operation from left to right.

foldcollection.fold(initial) { acc, e -> }

Accumulates value starting with initial value and applying operation to each element.

groupBycollection.groupBy { keySelector }

Groups elements of the original collection by the key returned by the given selector.

sortedBycollection.sortedBy { selector }

Returns a list of all elements sorted according to natural sort order of the selector.

distinctBycollection.distinctBy { selector }

Returns a list containing only elements from the given collection having distinct keys.

takecollection.take(n)

Returns a list containing first n elements.

dropcollection.drop(n)

Returns a list containing all elements except first n elements.

countcollection.count { predicate? }

Returns the number of elements matching the given predicate.

anycollection.any { predicate }

Returns true if at least one element matches the given predicate.

allcollection.all { predicate }

Returns true if all elements match the given predicate.

nonecollection.none { predicate }

Returns true if no elements match the given predicate.

sumOfcollection.sumOf { selector }

Returns the sum of all values produced by the selector function.

maxOfcollection.maxOf { selector }

Returns the largest value among all values produced by the selector function.

associateBycollection.associateBy { keySelector }

Returns a Map containing key-value pairs provided by the transform function.

partitioncollection.partition { predicate }

Splits the original collection into pair of lists by the given predicate.

ziplistA.zip(listB)

Returns a list of pairs built from the elements of this collection and other collection.