Source.unfold

Stream the result of a function as long as it returns a Some Optional.

Source operators

Signature

def unfold[S, E](s: S)(f: S ⇒ Option[(S, E)]): Source[E, NotUsed]

Description

Stream the result of a function as long as it returns a Some Optional. The value inside the option consists of a tuple pair where the first value is a state passed back into the next call to the function allowing to pass a state. The first invocation of the provided fold function will receive the zero state.

Can be used to implement many stateful sources without having to touch the more low level GraphStage API.

emits when there is demand and the unfold function over the previous state returns non empty value

completes when the unfold function returns an empty value

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.