kotlin-flow-extensions / hu.akarnokd.kotlin.flow

Package hu.akarnokd.kotlin.flow

Types

BehaviorSubject

class BehaviorSubject<T> : AbstractFlow<T>, SubjectAPI<T>

Caches one item and replays it to fresh collectors.

BufferingResumableCollector

open class BufferingResumableCollector<T> : Resumable

A collector that can buffer a fixed number of items and drain it with much less need to coordinate the resumption per items.

ConnectableFlow

interface ConnectableFlow<T> : Flow<T>

A possibly multicasting Flow that begins emitting values only when the connect method is called.

GroupedFlow

interface GroupedFlow<K, V> : Flow<V>

Represents a Flow with a group key.

ParallelFlow

interface ParallelFlow<out T>

Base interface for parallel stages in an operator

PublishSubject

class PublishSubject<T> : AbstractFlow<T>, SubjectAPI<T>

Multicasts items to any number of collectors when they are ready to receive.

ReplaySubject

class ReplaySubject<T> : AbstractFlow<T>, SubjectAPI<T>

Caches and replays some or all items to collectors.

Resumable

open class Resumable : AtomicReference<Continuation<Any>>

Primitive for suspending and resuming coroutines on demand

ResumableCollector

open class ResumableCollector<T> : Resumable

A collector that hosts a signal (value/error/completion) and allows waiting for the signal and a consumer to be ready to receive them.

SubjectAPI

interface SubjectAPI<T> : FlowCollector<T>, Flow<T>

Base interface for suspendable push signals emit, emitError and complete.

Extensions for External Classes

kotlinx.coroutines.flow.Flow

Functions

concatMap

fun <T, R> ParallelFlow<T>.concatMap(mapper: suspend (T) -> Flow<R>): ParallelFlow<R>

Maps the upstream value on each rail onto a Flow and emits their values in order on the same rail.

filter

fun <T> ParallelFlow<T>.filter(predicate: suspend (T) -> Boolean): ParallelFlow<T>

Filters the values of the upstream in parallel.

map

fun <T, R> ParallelFlow<T>.map(mapper: suspend (T) -> R): ParallelFlow<R>

Maps the values of the upstream in parallel.

range

fun range(start: Int, count: Int): Flow<Int>

Generates a range of ever increasing integer values.

reduce

fun <T, R> ParallelFlow<T>.reduce(seed: suspend () -> R, combine: suspend (R, T) -> R): ParallelFlow<R>

Reduces the source items into a single value on each rail and emits those.

fun <T> ParallelFlow<T>.reduce(combine: suspend (T, T) -> T): Flow<T>

Reduce the values within the parallel rails and then reduce the rails to a single result value.

sequential

fun <T> ParallelFlow<T>.sequential(): Flow<T>

Consumes the parallel upstream and turns it into a sequential flow again.

timer

fun timer(timeout: Long, unit: TimeUnit): Flow<Long>

Signal 0L after the given time passed

transform

fun <T, R> ParallelFlow<T>.transform(callback: suspend FlowCollector<R>.(T) -> Unit): ParallelFlow<R>

Transform each upstream item into zero or more emits for the downstream in parallel.