2
votes

Im trying to use the javadsl variant of Akka streams, and I seem to have hit a problem when I try to define a Flow which should take Pair elements.

Say, for example, I have defined a Flow which accepts incoming Strings and Pairs it with a boolean stating wether or not the String has a length of 5 or bigger:

final Flow<String, Pair<String, Boolean>, BoxedUnit> stringToPair = Flow
    .of(String.class)
    .map(s -> new Pair<>(s, s.length() >= 5));

This works fine. But the next step is for me to define a Flow which takes Pairs of String and Boolean and returns just the String again:

final Flow<Pair<String, Boolean>, String, BoxedUnit> pairToString = Flow
        .of(Pair.class)
        .map(p -> p.first());

I am not sure if I should create the pairToString flow with the .of(Pair.class) method because I dont know if and where the incoming Pair should be typed (like Pair<String, Boolean>)

Any help and / or pointers are greatly appreciated!

1

1 Answers

3
votes

For generic stream element types you can create a Flow using

Flow.<Pair<String, Boolean>> create()

which allows more freedom in this regard than Flow.of(...). Which one to choose is a matter of taste in all non-generic cases.