Skip to content

Instantly share code, notes, and snippets.

@daveray
Created August 29, 2013 20:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveray/6382916 to your computer and use it in GitHub Desktop.
Save daveray/6382916 to your computer and use it in GitHub Desktop.
Rx + Clojure Near-term Plans

Posted to Clojure Google Group, but it's not showing up there (https://groups.google.com/forum/#!topic/clojure/GITSKLmFM60), so...

In an effort to simplify the implementation and improve the RxJava experience for all JVM-based languages, we'll be dropping direct IFn support (and Groovy closure, Ruby proc, etc) in the next release. Instead, for each supported language (Scala, Groovy, and Clojure at the moment), we'll be providing a set of utility functions/macros/implicits to assist with interop. In the Clojure case, this will consist of a namespace, probably rx.lang.clojure, with the following helpers:

(defn fn* [f]) 
Takes a function f, and wraps it in an object that implements all
the various Rx FuncX interfaces
 
(defmacro fn [& body]) 
Makes an "anonymous" Rx FuncX object with body (multi-arities
and everything from clojure.core/fn are supported)

So usage would basically be as I noted in my message above:

(require '[rx.lang.clojure :as rx])
 
(-> my-observable
    (.map (rx/fn [v] (Long/parseLong v)))
    (.reduce (rx/fn* +)))

A similar function/macro pair will be provided for the Rx ActionX interfaces for which there's currently no direct support.

This will provide us with base Clojure interop support which is slightly more tedious to use than before. In the longer term, we'll be releasing a more expansive, idiomatic set of Clojure bindings. We're not quite there on that one though.

If anyone knows any reason this should not happen, speak now or forever hold your peace.

Cheers,

Dave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment