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
+87-32Lines changed: 87 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,90 @@
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:
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:
74
+
75
+
* 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()`.
76
+
* Most everything involving schedulers
77
+
* Most everything involving time
78
+
*`Observable.window` and `Observable.buffer`. Who knows which parts of these beasts to wrap?
79
+
80
+
Of course, contributions that cover these cases are welcome.
81
+
82
+
# Low-level Interop
3
83
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
84
5
-
# Basic Usage
85
+
##Basic Usage
6
86
7
-
## Requiring the interop namespace
87
+
###Requiring the interop namespace
8
88
The first thing to do is to require the namespace:
9
89
10
90
```clojure
@@ -19,7 +99,7 @@ or, at the REPL:
19
99
(require '[rx.lang.clojure.interop :as rx])
20
100
```
21
101
22
-
## Using rx/fn
102
+
###Using rx/fn
23
103
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
104
25
105
```clojure
@@ -34,7 +114,7 @@ If you already have a plain old Clojure function you'd like to use, you can pass
34
114
(.reduce (rx/fn* +)))
35
115
```
36
116
37
-
## Using rx/action
117
+
###Using rx/action
38
118
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
119
40
120
```clojure
@@ -46,7 +126,7 @@ The `rx/action` macro is identical to `rx/fn` except that the object returned im
46
126
(rx/action [] (println"Sequence complete"))))
47
127
```
48
128
49
-
## Using Observable/create
129
+
###Using Observable/create
50
130
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
131
52
132
```clojure
@@ -59,35 +139,10 @@ As of 0.17, `rx.Observable/create` takes an implementation of `rx.Observable$OnS
59
139
(.onCompleted s)))
60
140
```
61
141
62
-
# Gotchas
142
+
##Gotchas
63
143
Here are a few things to keep in mind when using this interop:
64
144
65
145
* Keep in mind the (mostly empty) distinction between `Func` and `Action` and which is used in which contexts
66
146
* 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
147
* 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
148
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