From 1424b2416755568440c0f5c8f2ce9507cc0980fa Mon Sep 17 00:00:00 2001 From: Thomas Nield Date: Wed, 15 Mar 2017 09:06:54 -0500 Subject: [PATCH 1/5] add several more operators for Observable, Flowable, etc... --- .../io/reactivex/rxkotlin/completable.kt | 15 +++++++ .../kotlin/io/reactivex/rxkotlin/flowable.kt | 24 +++++++++- .../kotlin/io/reactivex/rxkotlin/maybe.kt | 39 +++++++++++++++- .../io/reactivex/rxkotlin/observable.kt | 23 +++++++++- .../kotlin/io/reactivex/rxkotlin/operators.kt | 44 ------------------- .../kotlin/io/reactivex/rxkotlin/single.kt | 36 +++++++++++++++ .../io/reactivex/rxkotlin/subscribers.kt | 6 +-- 7 files changed, 135 insertions(+), 52 deletions(-) delete mode 100644 src/main/kotlin/io/reactivex/rxkotlin/operators.kt diff --git a/src/main/kotlin/io/reactivex/rxkotlin/completable.kt b/src/main/kotlin/io/reactivex/rxkotlin/completable.kt index 2200e78..dc19435 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/completable.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/completable.kt @@ -1,6 +1,8 @@ package io.reactivex.rxkotlin import io.reactivex.Completable +import io.reactivex.Flowable +import io.reactivex.Observable import io.reactivex.functions.Action import java.util.concurrent.Callable import java.util.concurrent.Future @@ -9,3 +11,16 @@ fun Action.toCompletable(): Completable = Completable.fromAction(this) fun Callable.toCompletable(): Completable = Completable.fromCallable(this) fun Future.toCompletable(): Completable = Completable.fromFuture(this) fun (() -> Any).toCompletable(): Completable = Completable.fromCallable(this) + + +// EXTENSION FUNCTION OPERATORS + +/** + * Merges the emissions of a Observable. Same as calling `flatMapSingle { it }`. + */ +fun Observable.mergeAllCompletables() = flatMapCompletable { it } + +/** + * Merges the emissions of a Flowable. Same as calling `flatMap { it }`. + */ +fun Flowable.mergeAllCompletables() = flatMapCompletable { it } diff --git a/src/main/kotlin/io/reactivex/rxkotlin/flowable.kt b/src/main/kotlin/io/reactivex/rxkotlin/flowable.kt index ce6fc54..554e705 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/flowable.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/flowable.kt @@ -61,4 +61,26 @@ inline fun Flowable<*>.ofType(): Flowable = ofType(R::class private fun Iterator.toIterable() = object : Iterable { override fun iterator(): Iterator = this@toIterable -} \ No newline at end of file +} + +//EXTENSION FUNCTION OPERATORS + +/** + * Merges the emissions of a Flowable>. Same as calling `flatMap { it }`. + */ +fun Flowable>.mergeAll() = flatMap { it } + + +/** + * Concatenates the emissions of an Flowable>. Same as calling `concatMap { it }`. + */ +fun Flowable>.concatAll() = concatMap { it } + + +/** + * Emits the latest `Flowable` emitted through an `Flowable>`. Same as calling `switchMap { it }`. + */ +fun Flowable>.switchLatest() = switchMap { it } + + +fun Flowable>.switchOnNext(): Flowable = Flowable.switchOnNext(this) diff --git a/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt b/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt index 1b9e9fe..0266ee2 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt @@ -1,6 +1,8 @@ package io.reactivex.rxkotlin +import io.reactivex.Flowable import io.reactivex.Maybe +import io.reactivex.Observable import java.util.concurrent.Callable import java.util.concurrent.Future @@ -10,4 +12,39 @@ fun Callable.toMaybe(): Maybe = Maybe.fromCallable(this) fun (() -> T).toMaybe(): Maybe = Maybe.fromCallable(this) inline fun Maybe.cast(): Maybe = cast(R::class.java) -inline fun Maybe.ofType(): Maybe = ofType(R::class.java) \ No newline at end of file +inline fun Maybe.ofType(): Maybe = ofType(R::class.java) + + + +// EXTENSION FUNCTION OPERATORS + +/** + * Merges the emissions of a Observable>. Same as calling `flatMapMaybe { it }`. + */ +fun Observable>.mergeAllMaybes() = flatMapMaybe { it } + +/** + * Merges the emissions of a Flowable>. Same as calling `flatMap { it }`. + */ +fun Flowable>.mergeAllMaybes() = flatMapMaybe { it } + +/** + * Concatenates the emissions of an Flowable>. + */ +fun Observable>.concatAllMaybes() = concatMap { it.toObservable() } + +/** + * Concatenates the emissions of an Flowable>. + */ +fun Flowable>.concatAllMaybes() = concatMap { it.toFlowable() } + +/** + * Emits the latest `Maybe` emitted through an `Flowable>`. + */ +fun Observable>.switchLatestMaybes() = switchMap { it.toObservable() } + +/** + * Emits the latest `Maybe` emitted through an `Flowable>`. + */ +fun Flowable>.switchLatestMaybes() = switchMap { it.toFlowable() } + diff --git a/src/main/kotlin/io/reactivex/rxkotlin/observable.kt b/src/main/kotlin/io/reactivex/rxkotlin/observable.kt index 50b3bce..fc491c5 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/observable.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/observable.kt @@ -61,4 +61,25 @@ inline fun Observable<*>.ofType(): Observable = ofType(R::c private fun Iterator.toIterable() = object : Iterable { override fun iterator(): Iterator = this@toIterable -} \ No newline at end of file +} + + +// EXTENSION FUNCTION OPERATORS + +/** + * Merges the emissions of an Observable>. Same as calling `flatMap { it }`. + */ +fun Observable>.mergeAll() = flatMap { it } + +/** + * Concatenates the emissions of an Observable>. Same as calling `concatMap { it }`. + */ +fun Observable>.concatAll() = concatMap { it } + +/** + * Emits the latest `Observable` emitted through an `Observable>`. Same as calling `switchMap { it }`. + */ +fun Observable>.switchLatest() = switchMap { it } + +fun Observable>.switchOnNext(): Observable = Observable.switchOnNext(this) + diff --git a/src/main/kotlin/io/reactivex/rxkotlin/operators.kt b/src/main/kotlin/io/reactivex/rxkotlin/operators.kt deleted file mode 100644 index 585aebe..0000000 --- a/src/main/kotlin/io/reactivex/rxkotlin/operators.kt +++ /dev/null @@ -1,44 +0,0 @@ -package io.reactivex.rxkotlin - -import io.reactivex.Flowable -import io.reactivex.Observable -import io.reactivex.Single - -/** - * Merges the emissions of an Observable>. Same as calling `flatMap { it }`. - */ -fun Observable>.mergeAll() = flatMap { it } - -/** - * Merges the emissions of a Flowable>. Same as calling `flatMap { it }`. - */ -fun Flowable>.mergeAll() = flatMap { it } - - -/** - * Concatenates the emissions of an Observable>. Same as calling `concatMap { it }`. - */ -fun Observable>.concatAll() = concatMap { it } - -/** - * Concatenates the emissions of an Flowable>. Same as calling `concatMap { it }`. - */ -fun Flowable>.concatAll() = concatMap { it } - - -fun Observable>.switchOnNext(): Observable = Observable.switchOnNext(this) - - -fun Flowable>.switchOnNext(): Flowable = Flowable.switchOnNext(this) - - -/** - * Emits the latest `Observable` emitted through an `Observable>`. Same as calling `switchMap { it }`. - */ -fun Observable>.switchLatest() = switchMap { it } - - -/** - * Emits the latest `Flowable` emitted through an `Flowable>`. Same as calling `switchMap { it }`. - */ -fun Flowable>.switchLatest() = switchMap { it } diff --git a/src/main/kotlin/io/reactivex/rxkotlin/single.kt b/src/main/kotlin/io/reactivex/rxkotlin/single.kt index 6afbcfc..661a7e4 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/single.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/single.kt @@ -1,5 +1,7 @@ package io.reactivex.rxkotlin +import io.reactivex.Flowable +import io.reactivex.Observable import io.reactivex.Single import java.util.concurrent.Callable import java.util.concurrent.Future @@ -10,3 +12,37 @@ fun Callable.toSingle(): Single = Single.fromCallable(this) fun (() -> T).toSingle(): Single = Single.fromCallable(this) inline fun Single.cast(): Single = cast(R::class.java) + + +// EXTENSION FUNCTION OPERATORS + +/** + * Merges the emissions of a Observable>. Same as calling `flatMapSingle { it }`. + */ +fun Observable>.mergeAllSingles() = flatMapSingle { it } + +/** + * Merges the emissions of a Flowable>. Same as calling `flatMap { it }`. + */ +fun Flowable>.mergeAllSingles() = flatMapSingle { it } + +/** + * Concatenates the emissions of an Flowable>. + */ +fun Observable>.concatAllSingles() = concatMap { it.toObservable() } + +/** + * Concatenates the emissions of an Flowable>. + */ +fun Flowable>.concatAllSingles() = concatMap { it.toFlowable() } + +/** + * Emits the latest `Single` emitted through an `Flowable>`. + */ +fun Observable>.switchLatestSingle() = switchMap { it.toObservable() } + +/** + * Emits the latest `Single` emitted through an `Flowable>`. + */ +fun Flowable>.switchLatestSingle() = switchMap { it.toFlowable() } + diff --git a/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt b/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt index c5e46d1..271c2db 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt @@ -1,10 +1,6 @@ package io.reactivex.rxkotlin -import io.reactivex.Completable -import io.reactivex.Flowable -import io.reactivex.Maybe -import io.reactivex.Observable -import io.reactivex.Single +import io.reactivex.* import io.reactivex.disposables.Disposable import java.lang.RuntimeException From bce2d7c213b9a61dc9b13f50c8dd0b77242b090e Mon Sep 17 00:00:00 2001 From: Thomas Nield Date: Wed, 15 Mar 2017 09:10:42 -0500 Subject: [PATCH 2/5] remove import io.reactivex.* --- src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt b/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt index 271c2db..c5e46d1 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/subscribers.kt @@ -1,6 +1,10 @@ package io.reactivex.rxkotlin -import io.reactivex.* +import io.reactivex.Completable +import io.reactivex.Flowable +import io.reactivex.Maybe +import io.reactivex.Observable +import io.reactivex.Single import io.reactivex.disposables.Disposable import java.lang.RuntimeException From 0b7a777b3391bc70daa02397ac232f47f38b0712 Mon Sep 17 00:00:00 2001 From: Thomas Nield Date: Thu, 16 Mar 2017 20:38:49 -0500 Subject: [PATCH 3/5] rid plural maybes in operator name --- src/main/kotlin/io/reactivex/rxkotlin/maybe.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt b/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt index 0266ee2..1e84e7e 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt @@ -41,10 +41,10 @@ fun Flowable>.concatAllMaybes() = concatMap { it.toFlowable() /** * Emits the latest `Maybe` emitted through an `Flowable>`. */ -fun Observable>.switchLatestMaybes() = switchMap { it.toObservable() } +fun Observable>.switchLatestMaybe() = switchMap { it.toObservable() } /** * Emits the latest `Maybe` emitted through an `Flowable>`. */ -fun Flowable>.switchLatestMaybes() = switchMap { it.toFlowable() } +fun Flowable>.switchLatestMaybe() = switchMap { it.toFlowable() } From 909490a1e7c820dc453d194e87d898bbccc0cdae Mon Sep 17 00:00:00 2001 From: Thomas Nield Date: Fri, 17 Mar 2017 18:43:47 -0500 Subject: [PATCH 4/5] rid some operators targeting `Observable` and `Observable` and Flowable counterparts, out of scope --- .../kotlin/io/reactivex/rxkotlin/maybe.kt | 21 ------------------- .../kotlin/io/reactivex/rxkotlin/single.kt | 21 ------------------- 2 files changed, 42 deletions(-) diff --git a/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt b/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt index 1e84e7e..e120519 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/maybe.kt @@ -27,24 +27,3 @@ fun Observable>.mergeAllMaybes() = flatMapMaybe { it } * Merges the emissions of a Flowable>. Same as calling `flatMap { it }`. */ fun Flowable>.mergeAllMaybes() = flatMapMaybe { it } - -/** - * Concatenates the emissions of an Flowable>. - */ -fun Observable>.concatAllMaybes() = concatMap { it.toObservable() } - -/** - * Concatenates the emissions of an Flowable>. - */ -fun Flowable>.concatAllMaybes() = concatMap { it.toFlowable() } - -/** - * Emits the latest `Maybe` emitted through an `Flowable>`. - */ -fun Observable>.switchLatestMaybe() = switchMap { it.toObservable() } - -/** - * Emits the latest `Maybe` emitted through an `Flowable>`. - */ -fun Flowable>.switchLatestMaybe() = switchMap { it.toFlowable() } - diff --git a/src/main/kotlin/io/reactivex/rxkotlin/single.kt b/src/main/kotlin/io/reactivex/rxkotlin/single.kt index 661a7e4..bc19286 100644 --- a/src/main/kotlin/io/reactivex/rxkotlin/single.kt +++ b/src/main/kotlin/io/reactivex/rxkotlin/single.kt @@ -25,24 +25,3 @@ fun Observable>.mergeAllSingles() = flatMapSingle { it } * Merges the emissions of a Flowable>. Same as calling `flatMap { it }`. */ fun Flowable>.mergeAllSingles() = flatMapSingle { it } - -/** - * Concatenates the emissions of an Flowable>. - */ -fun Observable>.concatAllSingles() = concatMap { it.toObservable() } - -/** - * Concatenates the emissions of an Flowable>. - */ -fun Flowable>.concatAllSingles() = concatMap { it.toFlowable() } - -/** - * Emits the latest `Single` emitted through an `Flowable>`. - */ -fun Observable>.switchLatestSingle() = switchMap { it.toObservable() } - -/** - * Emits the latest `Single` emitted through an `Flowable>`. - */ -fun Flowable>.switchLatestSingle() = switchMap { it.toFlowable() } - From a7a5495a0a5079e5e79e43259b86ae99d295e124 Mon Sep 17 00:00:00 2001 From: Thomas Nield Date: Sun, 19 Mar 2017 21:41:25 -0500 Subject: [PATCH 5/5] update version to 2.0.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5d01c9a..8041cd2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=2.0.0-RC2 +version=2.0.0 org.gradle.jvmargs=-Xms256m -Xmx1024m -XX:MaxPermSize=256m \ No newline at end of file