#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

@ -109,7 +109,7 @@ public class RateTransformationDocTest {
public void expandShouldRepeatLast() throws Exception {
//#expand-last
final Flow<Double, Double, NotUsed> lastFlow = Flow.of(Double.class)
.expand(d -> d, s -> new Pair<>(s, s));
.expand(in -> Stream.iterate(in, i -> i).iterator());
//#expand-last
final Pair<TestPublisher.Probe<Double>, Future<List<Double>>> probeFut = TestSource.<Double> probe(system)
@ -132,15 +132,11 @@ public class RateTransformationDocTest {
@SuppressWarnings("unused")
//#expand-drift
final Flow<Double, Pair<Double, Integer>, NotUsed> driftFlow = Flow.of(Double.class)
.expand(d -> new Pair<Double, Integer>(d, 0), t -> {
return new Pair<>(t, new Pair<>(t.first(), t.second() + 1));
});
.expand(d -> Stream.iterate(0, i -> i + 1).map(i -> new Pair<>(d, i)).iterator());
//#expand-drift
final TestLatch latch = new TestLatch(2, system);
final Flow<Double, Pair<Double, Integer>, NotUsed> realDriftFlow = Flow.of(Double.class)
.expand(d -> { latch.countDown(); return new Pair<Double, Integer>(d, 0); }, t -> {
return new Pair<>(t, new Pair<>(t.first(), t.second() + 1));
});
.expand(d -> { latch.countDown(); return Stream.iterate(0, i -> i + 1).map(i -> new Pair<>(d, i)).iterator(); });
final Pair<TestPublisher.Probe<Double>, TestSubscriber.Probe<Pair<Double, Integer>>> pubSub = TestSource.<Double> probe(system)
.via(realDriftFlow)