Skip to content

Commit a26a6d0

Browse files
committed
Update README
1 parent 1a36873 commit a26a6d0

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

language-adaptors/rxjava-kotlin/README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,37 @@
33
Kotlin has support for SAM (Single Abstract Method) Interfaces as Functions (i.e. Java 8 Lambdas). So you could use Kotlin in RxJava whitout this adaptor
44

55
```kotlin
6-
Observable.create(OnSubscribeFunc<String> {
7-
it!!.onNext("Hello")
8-
it.onCompleted()
6+
Observable.create(OnSubscribeFunc<String> { observer ->
7+
observer!!.onNext("Hello")
8+
observer.onCompleted()
99
Subscriptions.empty()
1010
})!!.subscribe { result ->
1111
a!!.received(result)
1212
}
1313
```
1414

15-
This adaptor exposes a set of Extension functions that allow a more idiomatic Kotlin usage
15+
In RxJava [0.17.0](https://github.com/Netflix/RxJava/releases/tag/0.17.0) version a new Subscriber type was included
1616

1717
```kotlin
18-
import rx.lang.kotlin.*
18+
Observable.create(object:OnSubscribe<String> {
19+
override fun call(subscriber: Subscriber<in String>?) {
20+
subscriber!!.onNext("Hello")
21+
subscriber.onCompleted()
22+
}
23+
})!!.subscribe { result ->
24+
a!!.received(result)
25+
}
26+
```
1927

20-
{(observer: Observer<in String>) ->
21-
observer.onNext("Hello")
22-
observer.onCompleted()
23-
Subscriptions.empty()!!
24-
}.asObservableFunc().subscribe { result ->
28+
(Due to a [bug in Kotlin's compiler](http://youtrack.jetbrains.com/issue/KT-4753) you can't use SAM with OnSubscribe)
29+
30+
This adaptor exposes a set of Extension functions that allow a more idiomatic Kotlin usage
31+
32+
```kotlin
33+
{(subscriber: Subscriber<in String>) ->
34+
subscriber.onNext("Hello")
35+
subscriber.onCompleted()
36+
}.asObservable().subscribe { result ->
2537
a!!.received(result)
2638
}
2739
```

language-adaptors/rxjava-kotlin/src/main/kotlin/rx/lang/kotlin/namespace.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import rx.Subscriber
2525

2626

2727
public fun<T> Function1<Subscriber<in T>, Unit>.asObservable(): Observable<T> {
28-
val v = this
2928
return Observable.create(object:OnSubscribe<T> {
3029
override fun call(t1: Subscriber<in T>?) {
31-
v(t1!!)
30+
this@asObservable(t1!!)
3231
}
3332

3433
})!!
3534
}
3635

36+
[deprecated("Use Function1<Subscriber<in T>, Unit>.asObservable()")]
3737
public fun<T> Function1<Observer<in T>, Subscription>.asObservableFunc(): Observable<T> {
3838
return Observable.create(OnSubscribeFunc<T>{ op ->
3939
this(op!!)

0 commit comments

Comments
 (0)