-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RxKotlin 2.0 Release Candidate (#95)
* Dependencies updated * Initial implementation of rxKotlin for rxJava2 * Code cleaning. Code review related fixes. * Whitespaces removed. * gitignore update * subscribers replaced by named args extension * subscribeBy non-null params * empty* methods removed flowable extensions added minor fixes * dependencies updated * subscribeBy method for Flowable * tests updated * minor tests refactoring * * JoinToString method and tests ported from rxKotlin 1.0 * Subjects removed * Operators added * Minor formatting fix * More formatting fixes * Refactor "subscription" references to "disposable" * refactor `flowable.kt` and `observable.kt` to match 1.x changes * add `Flowable` support for operators * update `single` to match 1.x changes * rid Subject functions * update readme to reflect `onComplete` * Fix 2.x extension tests * add Array<T>.toFlowable() * update and fix compile errors for tests in 2.x * move swtichOnNext() * git commit -m 'refactor package domain to io.reactivex.rxkotlin' * optimize imports
- Loading branch information
1 parent
97f0555
commit 3e005e6
Showing
23 changed files
with
245 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sun Feb 12 16:33:43 SGT 2017 | ||
#Sun Mar 05 07:47:21 SGT 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lang/kotlin/examples/retrofit/retrofit.kt → ...ex/rxkotlin/examples/retrofit/retrofit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/kotlin/rx/lang/kotlin/completable.kt → ...tlin/io/reactivex/rxkotlin/completable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.reactivex.rxkotlin | ||
|
||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.disposables.Disposable | ||
|
||
/** | ||
* disposable += observable.subscribe() | ||
*/ | ||
operator fun CompositeDisposable.plusAssign(disposable: Disposable) { | ||
add(disposable) | ||
} | ||
|
||
/** | ||
* Add the subscription to a CompositeSubscription. | ||
* @param compositeDisposable CompositeDisposable to add this subscription to | ||
* @return this instance | ||
*/ | ||
fun Disposable.addTo(compositeDisposable: CompositeDisposable): Disposable | ||
= apply { compositeDisposable.add(this) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/rx/lang/kotlin/maybe.kt → ...ain/kotlin/io/reactivex/rxkotlin/maybe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.reactivex.rxkotlin | ||
|
||
import io.reactivex.Flowable | ||
import io.reactivex.Observable | ||
import io.reactivex.Single | ||
|
||
/** | ||
* Merges the emissions of an Observable<Observable<T>>. Same as calling `flatMap { it }`. | ||
*/ | ||
fun <T : Any> Observable<Observable<T>>.mergeAll() = flatMap { it } | ||
|
||
/** | ||
* Merges the emissions of a Flowable<Flowable<T>>. Same as calling `flatMap { it }`. | ||
*/ | ||
fun <T : Any> Flowable<Flowable<T>>.mergeAll() = flatMap { it } | ||
|
||
|
||
/** | ||
* Concatenates the emissions of an Observable<Observable<T>>. Same as calling `concatMap { it }`. | ||
*/ | ||
fun <T : Any> Observable<Observable<T>>.concatAll() = concatMap { it } | ||
|
||
/** | ||
* Concatenates the emissions of an Flowable<Flowable<T>>. Same as calling `concatMap { it }`. | ||
*/ | ||
fun <T : Any> Flowable<Flowable<T>>.concatAll() = concatMap { it } | ||
|
||
|
||
fun <T : Any> Observable<Observable<T>>.switchOnNext(): Observable<T> = Observable.switchOnNext(this) | ||
|
||
|
||
fun <T : Any> Flowable<Flowable<T>>.switchOnNext(): Flowable<T> = Flowable.switchOnNext(this) | ||
|
||
|
||
/** | ||
* Emits the latest `Observable<T>` emitted through an `Observable<Observable<T>>`. Same as calling `switchMap { it }`. | ||
*/ | ||
fun <T : Any> Observable<Observable<T>>.switchLatest() = switchMap { it } | ||
|
||
|
||
/** | ||
* Emits the latest `Flowable<T>` emitted through an `Flowable<Flowable<T>>`. Same as calling `switchMap { it }`. | ||
*/ | ||
fun <T : Any> Flowable<Flowable<T>>.switchLatest() = switchMap { it } | ||
|
||
|
||
/** | ||
* Joins the emissions of a finite `Observable` into a `String`. | ||
* | ||
* @param separator is the dividing character(s) between each element in the concatenated `String` | ||
* | ||
* @param prefix is the preceding `String` before the concatenated elements (optional) | ||
* | ||
* @param postfix is the succeeding `String` after the concatenated elements (optional) | ||
*/ | ||
fun <T : Any> Observable<T>.joinToString(separator: String? = null, | ||
prefix: String? = null, | ||
postfix: String? = null | ||
): Single<String> = collect({ StringBuilder(prefix ?: "") }) { builder: StringBuilder, next: T -> | ||
builder.append(if (builder.length == prefix?.length ?: 0) "" else separator ?: "").append(next) | ||
}.map { it.append(postfix ?: "").toString() } | ||
|
||
|
||
|
||
/** | ||
* Joins the emissions of a finite `Flowable` into a `String`. | ||
* | ||
* @param separator is the dividing character(s) between each element in the concatenated `String` | ||
* | ||
* @param prefix is the preceding `String` before the concatenated elements (optional) | ||
* | ||
* @param postfix is the succeeding `String` after the concatenated elements (optional) | ||
*/ | ||
fun <T : Any> Flowable<T>.joinToString(separator: String? = null, | ||
prefix: String? = null, | ||
postfix: String? = null | ||
): Single<String> = collect({ StringBuilder(prefix ?: "") }) { builder: StringBuilder, next: T -> | ||
builder.append(if (builder.length == prefix?.length ?: 0) "" else separator ?: "").append(next) | ||
}.map { it.append(postfix ?: "").toString() } |
4 changes: 1 addition & 3 deletions
4
src/main/kotlin/rx/lang/kotlin/single.kt → ...in/kotlin/io/reactivex/rxkotlin/single.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.