arrow-fx-coroutines / arrow.fx.coroutines.stream / Stream / iterate
fun <A> iterate(initial: A, f: (A) -> A):
Stream
<A>
An infinite Stream
that repeatedly applies a given function to a start value.
initial is the first value emitted, followed by f(initial)
, then f(f(initial))
, and so on.
import arrow.fx.coroutines.stream.*
//sampleEnd
suspend fun main(): Unit =
Stream.iterateEffect(0) { it + 1 }
.take(10)
.toList()
.let(::println) // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
//sampleStart
Do you like Arrow?
✖