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

Add akka.japi.Either to Akka Java API helpers #25181

Closed
laszlovandenhoek opened this issue Jun 1, 2018 · 4 comments
Closed

Add akka.japi.Either to Akka Java API helpers #25181

laszlovandenhoek opened this issue Jun 1, 2018 · 4 comments

Comments

@laszlovandenhoek
Copy link
Contributor

As far as I can tell, scala.util.Either is not used anywhere in the public Java API of core Akka (or Akka Streams). However, it is used in akka-stream-contrib, particularly PartitionWith. Constructing a scala.util.Either from Java code is inconvenient; for example, Either.cond takes two by-name arguments but these are eagerly evaluated when called from Java, which often defeats the purpose of using Either at all.

I came up with this bit to scratch that particular itch:

import java.util.function.Supplier

object Either {
  def cond[A, B](condition: Boolean,
                 getB: Supplier[B],
                 getA: Supplier[A]): scala.Either[A,B] = {
    scala.Either.cond(condition, getB.get(), getA.get())
  }
}

...but I guess this is a bit light to include as a central library component as it stands. I think it could be a valuable addition, opening up new possibilities, but before fleshing it out and submitting a PR, I figured I'd open this issue as an RFC. In particular, I'm curious if the Akka team is open to adding an Either to the akka.japi package (in akka-actor), and if so, what features it should have and/or lack.

@laszlovandenhoek laszlovandenhoek changed the title Add akka.japi.Either to Add akka.japi.Either to Akka Java API helpers Jun 1, 2018
@patriknw
Copy link
Member

patriknw commented Jun 1, 2018

@laszlovandenhoek I think it would be better if you contribute a proper Java API to akka-stream-contrib. We don't have good experience with exposing Scala classes in Java APIs. E.g. Scala's Duration, Future, Option. They may seem harmless from a Scala developers perspective but just the fact that they have scala in the package name seems to scare Java developers. Therefore we try to not use such classes in Java APIs.

@He-Pin
Copy link
Member

He-Pin commented Jun 1, 2018

There is a vavr out there:)
But I have to agree with @patriknw, it's always scary for who don't know Scala much.

@laszlovandenhoek
Copy link
Contributor Author

I'll close this and continue here: akka/akka-stream-contrib#135

@patriknw
Copy link
Member

patriknw commented Jun 4, 2018

thanks

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

3 participants