You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: language-adaptors/rxjava-clojure/README.md
+93-32Lines changed: 93 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,96 @@
1
-
# Clojure Adaptor for RxJava
1
+
Clojure bindings for RxJava.
2
2
3
+
# Binaries
4
+
5
+
Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rxjava-clojure%22).
This library provides convenient, idiomatic Clojure bindings for RxJava.
37
+
38
+
The bindings try to present an API that will be comfortable and familiar to a Clojure programmer that's familiar with the sequence operations in `clojure.core`. It "fixes" several issues with using RxJava with raw Java interop, for example:
39
+
40
+
* Argument lists are in the "right" order. So in RxJava, the function applied in `Observable.map` is the second argument, while here it's the first argument with one or more Observables as trailing arguments
41
+
* Operators take normal Clojure functions as arguments, bypassing need for the interop described below
42
+
* Predicates accomodate Clojure's notion of truth
43
+
* Operators are generally names as they would be in `clojure.core` rather than the Rx names
44
+
45
+
There is no object wrapping going on. That is, all functions return normal `rx.Observable` objects, so you can always drop back to Java interop for anything that's missing in this wrapper.
46
+
47
+
## Basic Usage
48
+
Most functionality resides in the `rx.lang.clojure.core` namespace and for the most part looks like normal Clojure sequence manipulation:
*`group-by` val-fn variant isn't implemented in RxJava
76
+
* There are some functions for defining customer Observables and Operators (`subscriber`, `operator*`, `observable*`). I don't think these are really enough for serious operator implementation, but I'm hesitant to guess at an abstraction at this point. These will probably change dramatically.
77
+
78
+
## What's Missing
79
+
This library is an ongoing work in progress driven primarily by the needs of one team at Netflix. As such some things are currently missing:
80
+
81
+
* Highly-specific operators that we felt cluttered the API and were easily composed from existing operators, especially since we're in not-Java land. For example, `Observable.sumLong()`.
82
+
* Most everything involving schedulers
83
+
* Most everything involving time
84
+
*`Observable.window` and `Observable.buffer`. Who knows which parts of these beasts to wrap?
85
+
86
+
Of course, contributions that cover these cases are welcome.
87
+
88
+
# Low-level Interop
3
89
This adaptor provides functions and macros to ease Clojure/RxJava interop. In particular, there are functions and macros for turning Clojure functions and code into RxJava `Func*` and `Action*` interfaces without the tedium of manually reifying the interfaces.
4
90
5
-
# Basic Usage
91
+
##Basic Usage
6
92
7
-
## Requiring the interop namespace
93
+
###Requiring the interop namespace
8
94
The first thing to do is to require the namespace:
9
95
10
96
```clojure
@@ -19,7 +105,7 @@ or, at the REPL:
19
105
(require '[rx.lang.clojure.interop :as rx])
20
106
```
21
107
22
-
## Using rx/fn
108
+
###Using rx/fn
23
109
Once the namespace is required, you can use the `rx/fn` macro anywhere RxJava wants a `rx.util.functions.Func` object. The syntax is exactly the same as `clojure.core/fn`:
24
110
25
111
```clojure
@@ -34,7 +120,7 @@ If you already have a plain old Clojure function you'd like to use, you can pass
34
120
(.reduce (rx/fn* +)))
35
121
```
36
122
37
-
## Using rx/action
123
+
###Using rx/action
38
124
The `rx/action` macro is identical to `rx/fn` except that the object returned implements `rx.util.functions.Action` interfaces. It's used in `subscribe` and other side-effect-y contexts:
39
125
40
126
```clojure
@@ -46,7 +132,7 @@ The `rx/action` macro is identical to `rx/fn` except that the object returned im
46
132
(rx/action [] (println"Sequence complete"))))
47
133
```
48
134
49
-
## Using Observable/create
135
+
###Using Observable/create
50
136
As of 0.17, `rx.Observable/create` takes an implementation of `rx.Observable$OnSubscribe` which is basically an alias for `rx.util.functions.Action1` that takes an `rx.Subscriber` as its argument. Thus, you can just use `rx/action` when creating new observables:
51
137
52
138
```clojure
@@ -59,35 +145,10 @@ As of 0.17, `rx.Observable/create` takes an implementation of `rx.Observable$OnS
59
145
(.onCompleted s)))
60
146
```
61
147
62
-
# Gotchas
148
+
##Gotchas
63
149
Here are a few things to keep in mind when using this interop:
64
150
65
151
* Keep in mind the (mostly empty) distinction between `Func` and `Action` and which is used in which contexts
66
152
* If there are multiple Java methods overloaded by `Func` arity, you'll need to use a type hint to let the compiler know which one to choose.
67
153
* Methods that take a predicate (like filter) expect the predicate to return a boolean value. A function that returns a non-boolean value will result in a `ClassCastException`.
68
154
69
-
# Binaries
70
-
71
-
Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rxjava-clojure%22).
0 commit comments