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 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..e120519 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,18 @@ 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 } 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..bc19286 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,16 @@ 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 }