Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace scala.Either in PartitionWith Java API #135

Open
laszlovandenhoek opened this issue Jun 3, 2018 · 3 comments
Open

replace scala.Either in PartitionWith Java API #135

laszlovandenhoek opened this issue Jun 3, 2018 · 3 comments

Comments

@laszlovandenhoek
Copy link

The Java API of PartitionWith takes a function that yields a scala.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?

  • a boolean and two Suppliers?
  • some Either from a Java library like cyclops-react?
  • something else?
@patriknw
Copy link
Member

patriknw commented Jun 4, 2018

May I ask what benefits PartitionWith has over using the akka.stream.javadsl.akka.stream.Partition and separate map operations in the downstream legs?

@laszlovandenhoek
Copy link
Author

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 😉

@patriknw
Copy link
Member

patriknw commented Jun 4, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants