akka/akka — pull request #15041 by patriknw (2014-04-23 08:10:14+00:00)
Title: +str #15034 Add Flow javadsl

* First stab for early review only

This is how it looks like:

final ActorSystem system = ActorSystem.create("Sys");
final MaterializerSettings settings = MaterializerSettings.create();
final FlowMaterializer materializer = FlowMaterializer.create(settings, system);

final String[] lookup = { "a", "b", "c", "d", "e", "f" };
final java.lang.Iterable input = Arrays.asList(0, 1, 2, 3, 4, 5);
Flow.create(input).drop(2).take(3).
map(new Function() {
public String apply(Integer elem) {
return lookup[elem];
}
}).
filter(new Predicate() {
public boolean defined(String elem) {
return !elem.equals("c");
}
}).
grouped(2).mapConcat(new Function, java.util.List>() {
public java.util.List apply(java.util.List elem) {
return elem;
}
}).fold("", new Function2() {
public String apply(String acc, String elem) {
return acc + elem;
}
}).foreach(new Procedure() {
public void apply(String elem) {
System.out.println(elem);
}
}).consume(materializer);

And in Java8:

final ActorSystem system = ActorSystem.create("Sys");
final MaterializerSettings settings = MaterializerSettings.create();
final FlowMaterializer materializer = FlowMaterializer.create(settings, system);

final String[] lookup = { "a", "b", "c", "d", "e", "f" };
final java.lang.Iterable input = Arrays.asList(0, 1, 2, 3, 4, 5);
Flow.create(input).drop(2).take(3).
map(elem -> lookup[elem]).
filter(elem -> !elem.equals("c")).
grouped(2).
mapConcat(elem -> elem).
fold("", (acc, elem) -> acc + elem).
foreach(elem -> System.out.println(elem)).
consume(materializer);