This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-27
Channels
- # aleph (2)
- # beginners (19)
- # boot (15)
- # cider (1)
- # cljsrn (1)
- # clojure (68)
- # clojure-austin (12)
- # clojure-dev (2)
- # clojure-france (6)
- # clojure-italy (46)
- # clojure-russia (45)
- # clojure-spec (55)
- # clojure-uk (41)
- # clojurescript (117)
- # component (15)
- # cursive (54)
- # datomic (24)
- # events (2)
- # funcool (1)
- # instaparse (4)
- # klipse (30)
- # lein-figwheel (3)
- # leiningen (4)
- # luminus (4)
- # om (10)
- # onyx (13)
- # parinfer (36)
- # proton (1)
- # reagent (1)
- # ring (2)
- # ring-swagger (1)
- # rum (19)
- # test-check (6)
- # testing (9)
- # untangled (1)
Anyone here able to shed some wisdom on using java 8 closures from clojure?
Specifically I'm using http://grpc.io as an application server, and trying to get away with a thin java layer that calls out to clojure for everything.
The question is, how do you call back into the java context once you've marshalled a response object on the clojure side?
It'd be extremely convenient to be able to do something like:
...but it seems you can't?
What you’re being passed is an object that implements a Functional interface.
I suspect there’s a .call()
method on it?
What have you tried @shadowmint ?
I've tried doing that I wrote up there:
Calling the IFn with a closure on it:
handler.invoke(..., () -> { ... })
but closures are not object?
and the IFn interface for clojure functions is overloaded with any number of object artguments
but none of them match for a closure type?
...I mean, I can have a custom object, with a method on it called 'callback', pass the object in, and invoke the method on it using (.callback promise response).
It's just semantically irritating.
@shadowmint Ah, I thought you had the Java side working and just needed to know how to call the closure from Clojure — but I see you can’t even compile the Java code.
The problem here is that Java uses the type of the argument to decide how to bundle up the closure as a Java object. IFn
just accepts objects, so it doesn’t give the Java compiler enough of a "hint" to be able to deduce that. You might be able to insert a Java cast here to satisfy the compiler but I’m not sure.
Maybe java.util.function.Consumer<HelloReply>
would be a good thing to try first — and then in your Clojure code, call (.accept callback reply)
. But you’ll have to read the java.util.function
package docs and try a few things I suspect.