fold

Fold over emitted element with a function, where each invocation will get the new element and the result from the previous fold invocation.

Sink stages

Signature

def fold[U, T](zero: U)(f: (U, T) ⇒ U): Sink[T, Future[U]]

Description

Fold over emitted element with a function, where each invocation will get the new element and the result from the previous fold invocation. The first invocation will be provided the zero value.

Materializes into a Future CompletionStage that will complete with the last state when the stream has completed.

This stage allows combining values into a result without a global mutable state by instead passing the state along between invocations.

@@@div { .callout }

cancels never

backpressures when the previous fold function invocation has not yet completed

@@@div

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.