Introduces fold as a Flow transformation and generalizes Sink.fold to be Flow.fold + Sink.head

Conflicts:
	akka-stream/src/main/scala/akka/stream/impl/ActorMaterializerImpl.scala
	akka-stream/src/main/scala/akka/stream/impl/Stages.scala
	akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala
This commit is contained in:
Viktor Klang 2015-06-14 03:12:30 -04:00
parent 849875ad90
commit 36abbb4234
18 changed files with 204 additions and 209 deletions

View file

@ -96,9 +96,7 @@ final class Flow[-In, +Out, +Mat](private[stream] override val module: Module)
* value of the current flow (ignoring the given Sinks value), use
* [[Flow#toMat[Mat2* toMat]] if a different strategy is needed.
*/
def to[Mat2](sink: Graph[SinkShape[Out], Mat2]): Sink[In, Mat] = {
toMat(sink)(Keep.left)
}
def to[Mat2](sink: Graph[SinkShape[Out], Mat2]): Sink[In, Mat] = toMat(sink)(Keep.left)
/**
* Connect this [[Flow]] to a [[Sink]], concatenating the processing steps of both.
@ -541,6 +539,25 @@ trait FlowOps[+Out, +Mat] {
*/
def scan[T](zero: T)(f: (T, Out) T): Repr[T, Mat] = andThen(Scan(zero, f.asInstanceOf[(Any, Any) Any]))
/**
* Similar to `scan` but only emits its result when the upstream completes,
* after which it also completes. Applies the given function towards its current and next value,
* yielding the next current value.
*
* If the function `f` throws an exception and the supervision decision is
* [[akka.stream.Supervision.Restart]] current value starts at `zero` again
* the stream will continue.
*
* '''Emits when''' upstream completes
*
* '''Backpressures when''' downstream backpressures
*
* '''Completes when''' upstream completes
*
* '''Cancels when''' downstream cancels
*/
def fold[T](zero: T)(f: (T, Out) T): Repr[T, Mat] = andThen(Fold(zero, f.asInstanceOf[(Any, Any) Any]))
/**
* Chunk up this stream into groups of elements received within a time window,
* or limited by the given number of elements, whatever happens first.