mixite icon indicating copy to clipboard operation
mixite copied to clipboard

Use java.lang.Optional on JVM

Open drekbour opened this issue 6 years ago • 7 comments

Use expect / actual to allow Java 8 to provide the proper Optional implementation.

  • https://stackoverflow.com/questions/59006733/kotlin-multiplatform-support-for-optional/59007511?noredirect=1#comment104264493_59007511
  • https://github.com/h0tk3y/mpp-optional-demo

drekbour avatar Nov 23 '19 19:11 drekbour

We already have Maybe in Cobalt which we could use in Mixite to fix this, but I'm waiting for Arrow to become a MPP project (it is going to happen soon), then we could just use their implementation.

adam-arold avatar Nov 24 '19 19:11 adam-arold

Yes. It was that Maybe that had me shivering and raising this :)

drekbour avatar Nov 24 '19 19:11 drekbour

So the Maybe is there because of MPP. We might be able to use Optional on the JVM but there is no such construct for Javascript / Native.

adam-arold avatar Nov 24 '19 19:11 adam-arold

I see that Optional + Kotlin is a huge talking point in general. Should Mixite even bother? Or perhaps simply supply a JVM-only HexagonalGridDecorator which converts Hex? to Optional<Hex>.

Certainly all the "internal" uses of Maybe should be removed IMO!

drekbour avatar Nov 24 '19 20:11 drekbour

I'm not sure I follow. The problem in general is that we have to maintain API compatibility with Java, so that's why we have Maybe. It is going to be better when we can switch to Arrow's Option.

adam-arold avatar Nov 24 '19 20:11 adam-arold

Looks impressive. Arrow appears to be a full-FP attempt (every language has one!) however modular they present it as. Do you feel that introducing the arrowverse is a little heavy for a small lib (like when hexameter enforced rxjava).

I'm not massively troubled but IMO Optional isn't adding much here (hence why KT doesn't have it). Personally I would deprecate those methods and move away rather than reinforcing the position by using a 3rd-party impl.

drekbour avatar Nov 24 '19 21:11 drekbour

What alternative do we have to Optional? I don't really want to use nullable variables.

adam-arold avatar Nov 29 '19 20:11 adam-arold