#19444 simplify signature of FlowOps.expand

Any previous usage can be represented in this fashion while typically
saving one function allocation and also saving the function literal’s
syntax overhead (for the seed). Plus a new feature: the provided
iterator does not have to be infinite, limiting how far expand is
allowed to go.
This commit is contained in:
Roland Kuhn 2016-01-18 11:29:14 +01:00
parent a12451e007
commit 7463c50fc9
16 changed files with 127 additions and 151 deletions

View file

@ -1253,7 +1253,7 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
*
* '''Emits when''' downstream stops backpressuring
*
* '''Backpressures when''' downstream backpressures
* '''Backpressures when''' downstream backpressures or iterator runs emtpy
*
* '''Completes when''' upstream completes
*
@ -1263,11 +1263,8 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
* @param extrapolate Takes the current extrapolation state to produce an output element and the next extrapolation
* state.
*/
def expand[S, U](seed: function.Function[Out, S], extrapolate: function.Function[S, akka.japi.Pair[U, S]]): javadsl.Source[U, Mat] =
new Source(delegate.expand(seed(_))(s {
val p = extrapolate(s)
(p.first, p.second)
}))
def expand[U](extrapolate: function.Function[Out, java.util.Iterator[U]]): javadsl.Source[U, Mat] =
new Source(delegate.expand(in extrapolate(in).asScala))
/**
* Adds a fixed size buffer in the flow that allows to store elements from a faster upstream until it becomes full.