Chain

interface Chain<out T> : Flow<T>

A not-necessary-Markov chain of some type

Parameters

T

the chain element type

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun collect(collector: FlowCollector<T>)
Link copied to clipboard
abstract suspend fun fork(): Chain<T>

Create a copy of current chain state. Consuming resulting chain does not affect initial chain.

Link copied to clipboard
abstract suspend fun next(): T

Generate next value, changing state if needed

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
fun <R> Chain<R>.asSequence(): Sequence<R>

Represent a chain as a sequence

Link copied to clipboard
fun <T, R> Chain<T>.combine(mapper: suspend (Chain<T>) -> R): Chain<R>

Map the whole chain

Link copied to clipboard
fun <T, S, R> Chain<T>.combineWithState(state: S, stateFork: (S) -> S, mapper: suspend S.(Chain<T>) -> R): Chain<R>
Link copied to clipboard
fun <T> Chain<T>.filter(block: (T) -> Boolean): Chain<T>

block must be a pure function or at least not use external random variables, otherwise fork could be broken

Link copied to clipboard
operator fun <R> Chain<R>.iterator(): Iterator<R>

Represent a chain as regular iterator (uses blocking calls)

Link copied to clipboard
fun <T, R> Chain<T>.map(func: suspend (T) -> R): Chain<R>

Map the chain result using suspended transformation. Initial chain result can no longer be safely consumed since mapped chain consumes tokens. Accepts regular transformation function.

Link copied to clipboard
inline suspend fun <T : Any> Chain<T>.nextBuffer(size: Int): Buffer<T>
Link copied to clipboard
fun <T, U, R> Chain<T>.zip(other: Chain<U>, block: suspend (T, U) -> R): Chain<R>

Zip two chains together using given transformation

Sources

Link copied to clipboard