StatefulChain

class StatefulChain<S, out R>(state: S, seed: S.() -> R, forkState: (S) -> S, gen: suspend S.(R) -> R) : Chain<R>

A chain with possibly mutable state. The state must not be changed outside the chain. Two chins should never share the state.

Parameters

S

the state of the chain.

forkState

the function to copy current state without modifying it.

Constructors

Link copied to clipboard
fun <S, out R> StatefulChain(state: S, seed: S.() -> R, forkState: (S) -> S, gen: suspend S.(R) -> R)

Functions

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

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

Link copied to clipboard
open suspend override fun next(): R

Generate next value, changing state if needed

Link copied to clipboard
fun value(): R?

Properties

Link copied to clipboard
val gen: suspend S.(R) -> R
Link copied to clipboard
var value: R? = null

Sources

Link copied to clipboard