Skip to content

daveray/rx-clj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THESE BINDINDS HAVE BEEN SUBSUMED BY THE OFFICIAL RxClojure BINDINGS HERE: https://github.com/ReactiveX/RxClojure/

rx-clj

Notional Clojure bindings for RxJava. The main goal is to provide Rx versions of all the sequence operators in clojure.core, building on top of RxJava whenever possible. This will make it much more natural for a Clojure programmer to use RxJava when everything has the same "shape" as the Clojure functions they're familiar with. The biggies include:

  • Order of arguments to sequence operators
  • Observable/zip is just Clojure's map with multiple arguments
  • Predicates with non-Boolean return values
  • Observable/toList is just a whimpy version of clojure.core/into
  • Consistent naming like Observable/scan to reductions, Observable/skip to drop, etc.

For example, in RxJava, the signature of Observable.map is [xs f], but in Clojure, it's [f & xs]. Similarly, a filter predicate in Rx must return an honest-to-god Boolean, whereas Clojure's filter is happy with anything truthy. So instead of slightly unfamiliar code like this:

  (-> (Observable/from (slurp "words.txt"))
      (.map #(Character/toLowerCase %))
      (.filter (comp boolean #{\a \e \i \o \u}))
      (.reduce {} (fn [m v] (update-in m [v] (fnil inc 0)))))

you write code like this:

  (->> (rx/seq (slurp "words.txt"))
       (rx/map #(Character/toLowerCase %))
       (rx/filter #{\a \e \i \o \u})
       (rx/reduce (fn [m v] (update-in m [v] (fnil inc 0))) {}))

Note the idiomatic use of ->>, a set as a filter, and order of args to reduce. In either case, the result is an observable sequence.

See test/rx_clj/core_test.clj

Usage

This is just an idea. Don't use it. Slings and arrows welcomed.

LICENSE

Copyright 2013 Netflix, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Notional RxJava + Clojure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published