Return an empty (identity transformation) FlowBuilder based on the initial and context types.
Return an empty (identity transformation) FlowBuilder in which the initial type and the context type are the same.
A FlowBuilder provides tools for cunstructing an akka.stream Flow that transforms a FlowResult into another FlowResult. More explicitly, it is used to construct a Flow[FlowResult[I, Ctx], FlowResult[T, Ctx], akka.NotUsed]. Here I is thought of as the initial or input type, T is the terminal or output type, and Ctx is the context type which remains unchanged throughout the flow.
We prefer to transform FlowResults rather than the raw types I and T because it allows us to carry along all the extra information contained in the FlowResult. Namely, the context, the success/failure status, and the metadata. FlowBuilder makes it easy to transform the underlying types without affecting this context, and will transparently propogate failures.
val flow: Flow[FlowResult[Int, Int], FlowResult[String, Int], akka.NotUsed] = FlowBuilder.simple[Int] .map(i => i * 2) .flatMap { case i if i < 0 => Failure(new Exception("number is negative!")) case i => Success(i) }.mapWithContext((i, context, metadata) => s"Value: $i, Context: $context") .flow This starts with an initial Flow containing FlowResults of integers (and with context as the initia int value). It then: