Open laszlovandenhoek opened 6 years ago
May I ask what benefits PartitionWith
has over using the akka.stream.javadsl.akka.stream.Partition
and separate map
operations in the downstream legs?
I see one important benefit: clarity about the purpose of the split, by allowing a concise, atomic formulation of the difference between the two outputs. You cannot specify both map
operations in a one-liner.
Another (possibly less convincing) argument: if the Either
reduces the size of the input element, it saves you from passing a "full" element to another stage, only to reduce it there with a map
, as you would with Partition
.
A third, completely arbitrary and subjective reason would be that my highest-voted StackOverflow answer concerns PartitionWith
:wink:
For the Java API I'd suggest creating a custom class, PartitionWith.Output<A, B>
with clear factory methods such as PartitionWith.selectLeft(A element)
, PartitionWith.selectRight(B element)
.
The Java API of
PartitionWith
takes a function that yields ascala.Either
. Constructing that from Java is cumbersome.Either.cond
comes close but by-name laziness is not retained.I would like to replace the
Either
with something else, but what should it be?Supplier
s?Either
from a Java library like cyclops-react?