Chain

interface Chain<out T> : Flow<T>

A not-necessary-Markov chain of some type

Parameters

T
  • the chain element type

Types

Companion
Link copied to clipboard
common
object Companion

Functions

collect
Link copied to clipboard
common
open suspend override fun collect(collector: FlowCollector<T>)
fork
Link copied to clipboard
common
abstract suspend fun fork(): Chain<T>
Create a copy of current chain state.
next
Link copied to clipboard
common
abstract suspend fun next(): T
Generate next value, changing state if needed

Inheritors

BufferChain
Link copied to clipboard
BlockingChain
Link copied to clipboard
SimpleChain
Link copied to clipboard
MarkovChain
Link copied to clipboard
StatefulChain
Link copied to clipboard
ConstantChain
Link copied to clipboard

Extensions

asSequence
Link copied to clipboard
fun <R> Chain<R>.asSequence(): Sequence<R>
Represent a chain as a sequence
collect
Link copied to clipboard
common
fun <T, R> Chain<T>.collect(mapper: suspend (Chain<T>) -> R): Chain<R>
Map the whole chain
collectWithState
Link copied to clipboard
common
fun <T, S, R> Chain<T>.collectWithState(state: S, stateFork: (S) -> S, mapper: suspend S.(Chain<T>) -> R): Chain<R>
filter
Link copied to clipboard
common
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
iterator
Link copied to clipboard
operator fun <R> Chain<R>.iterator(): Iterator<R>
Represent a chain as regular iterator (uses blocking calls)
map
Link copied to clipboard
common
fun <T, R> Chain<T>.map(func: suspend (T) -> R): Chain<R>
Map the chain result using suspended transformation.
nextBuffer
Link copied to clipboard
common
inline suspend fun <T : Any> Chain<T>.nextBuffer(size: Int): Buffer<T>
zip
Link copied to clipboard
common
fun <T, U, R> Chain<T>.zip(other: Chain<U>, block: suspend (T, U) -> R): Chain<R>
Zip two chains together using given transformation