CollectorI

A Collector accumulates information from elements coming from some data source, usually a kotlinx.coroutines.flow.Flow or Iterable.

The accumulation is done in three phases:

  • Initialization of some (mutable) accumulator (supply)

  • Updating the accumulator with each value (accumulate)

  • Finalize the work, and extract the final result (finish)

This interface is heavily influenced by Java's Collector and Haskell's foldl library.

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
abstract suspend fun accumulate(current: InternalAccumulator, value: Value)
Link copied to clipboard
open fun <P> contramap(transform: suspend (P) -> Value): Collector<P, Result>

Applies a function over each element in the data source, before giving it to the collector.

Link copied to clipboard
abstract suspend fun finish(current: InternalAccumulator): Result
Link copied to clipboard
open fun <S> map(transform: suspend (Result) -> S): Collector<Value, S>

Performs additional work during the finalization phase, by applying a function to the end result.

Link copied to clipboard
abstract suspend fun supply(): InternalAccumulator
Link copied to clipboard
open fun <B, S> zip(other: CollectorI<B, @UnsafeVariance Value, S>): Collector<Value, Pair<Result, S>>

Combines two Collectors by performing the phases of each of them in parallel.

open fun <B, S, V> zip(other: CollectorI<B, @UnsafeVariance Value, S>, combine: suspend (Result, S) -> V): Collector<Value, V>

Combines two Collectors by performing the phases of each of them in parallel, and then combining the end result in a final step.