Who's HOFs on first?

Michael Bayne <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <CAOqP6L2fHDEUeMC3LV12jEn+Qpe4GkifiS+dXNoK3tr=QV3eWw@mail.gmail.com>
I'm working on a library that aims to be usable from various JVM languages
(Scala, Java, Kotlin, eventually more), and the API contains higher-order
functions. Ideally I'd like such calls to use the "natural" expression of
HOFs for each language and not require the use of adapter functions.

There are two routes that seem appealing:

1. Use Scala's FunctionN types and hope that the roadmap entry "Turn
FunctionN into Functional Interfaces, so that Java 8 code can call
higher-order methods in Scala without a wrapper." eventually happens.

2. Use Java's Function/Predicate etc. types and hope that eventually all of
the situations where code works with Scala functions but doesn't work for
SAMs eventually get ironed out. (This is the approach I tried initially and
then backed out of because it was making the library too annoying to use
from Scala.)

I couldn't find an issue in JIRA tracking the progress of #1, nor any
information about it on the Interwebs other than the single line in the
roadmap, so maybe even considering that option is foolish.

I'm just seeking advice, from anyone who is in the trenches on this front,
on which is likely to be the approach least fraught with pain and
frustration (I'm already deeply aware of the reality that trying to write
non-trivial code for use by multiple JVM languages is a road paved with
pain and frustration, so I'm not pointing fingers here).

Thus far, I've managed to achieve the worst of both worlds by having
overloaded versions of HOF-taking methods, one with Scala's function types
and one with Java's. Java and Kotlin are fine with that because Scala's
types are not SAMs and so they ignore them, but scalac freaks out about
this in a wide variety of circumstances. I'd prefer to move away from this
approach so that my (written in Scala) library is not annoying to use from
Scala.

Thanks!

-- [email protected]

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.