Skip to content

Commit

Permalink
Merge pull request #176 from trello/dlew/kotlin-extensions
Browse files Browse the repository at this point in the history
Filled out Kotlin extensions
  • Loading branch information
dlew authored Nov 8, 2016
2 parents bac6f42 + 533f655 commit 9832bd9
Showing 1 changed file with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,105 @@ package com.trello.rxlifecycle2.kotlin

import android.view.View
import com.trello.rxlifecycle2.LifecycleProvider
import com.trello.rxlifecycle2.RxLifecycle
import com.trello.rxlifecycle2.android.RxLifecycleAndroid
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.functions.Function

// RxLifecycle extensions

fun <T, E> Observable<T>.bind(lifecycle: Observable<E>): Observable<T>
= this.compose<T>(RxLifecycle.bind(lifecycle))

fun <T, E> Observable<T>.bindUntilEvent(lifecycle: Observable<E>, event: E): Observable<T>
= this.compose<T>(RxLifecycle.bindUntilEvent(lifecycle, event))

fun <T, E> Observable<T>.bind(lifecycle: Observable<E>, correspondingEvents: Function<E, E>): Observable<T>
= this.compose<T>(RxLifecycle.bind(lifecycle, correspondingEvents))

fun <T, E> Flowable<T>.bind(lifecycle: Observable<E>): Flowable<T>
= this.compose<T>(RxLifecycle.bind(lifecycle))

fun <T, E> Flowable<T>.bindUntilEvent(lifecycle: Observable<E>, event: E): Flowable<T>
= this.compose<T>(RxLifecycle.bindUntilEvent(lifecycle, event))

fun <T, E> Flowable<T>.bind(lifecycle: Observable<E>, correspondingEvents: Function<E, E>): Flowable<T>
= this.compose<T>(RxLifecycle.bind(lifecycle, correspondingEvents))

fun <T, E> Single<T>.bind(lifecycle: Observable<E>): Single<T>
= this.compose<T>(RxLifecycle.bind(lifecycle))

fun <T, E> Single<T>.bindUntilEvent(lifecycle: Observable<E>, event: E): Single<T>
= this.compose<T>(RxLifecycle.bindUntilEvent(lifecycle, event))

fun <T, E> Single<T>.bind(lifecycle: Observable<E>, correspondingEvents: Function<E, E>): Single<T>
= this.compose<T>(RxLifecycle.bind(lifecycle, correspondingEvents))

fun <T, E> Maybe<T>.bind(lifecycle: Observable<E>): Maybe<T>
= this.compose<T>(RxLifecycle.bind(lifecycle))

fun <T, E> Maybe<T>.bindUntilEvent(lifecycle: Observable<E>, event: E): Maybe<T>
= this.compose<T>(RxLifecycle.bindUntilEvent(lifecycle, event))

fun <T, E> Maybe<T>.bind(lifecycle: Observable<E>, correspondingEvents: Function<E, E>): Maybe<T>
= this.compose<T>(RxLifecycle.bind(lifecycle, correspondingEvents))

fun <E> Completable.bind(lifecycle: Observable<E>): Completable
= this.compose(RxLifecycle.bind<Any, E>(lifecycle))

fun <E> Completable.bindUntilEvent(lifecycle: Observable<E>, event: E): Completable
= this.compose(RxLifecycle.bindUntilEvent<Any, E>(lifecycle, event))

fun <E> Completable.bind(lifecycle: Observable<E>, correspondingEvents: Function<E, E>): Completable
= this.compose(RxLifecycle.bind<Any, E>(lifecycle, correspondingEvents))

// RxLifecycleAndroid extensions

fun <T, E> Observable<T>.bindToLifecycle(provider: LifecycleProvider<E>): Observable<T>
= this.compose<T>(provider.bindToLifecycle<T>())
= this.compose<T>(provider.bindToLifecycle<T>())

fun <T, E> Observable<T>.bindUntilEvent(provider: LifecycleProvider<E>, event: E): Observable<T>
= this.compose<T>(provider.bindUntilEvent(event))
= this.compose<T>(provider.bindUntilEvent(event))

fun <T> Observable<T>.bindToLifecycle(view: View): Observable<T>
= this.compose<T>(RxLifecycleAndroid.bindView(view))
= this.compose<T>(RxLifecycleAndroid.bindView(view))

fun <E> Completable.bindToLifecycle(provider: LifecycleProvider<E>): Completable
= this.compose(provider.bindToLifecycle<Completable>())
fun <T, E> Flowable<T>.bindToLifecycle(provider: LifecycleProvider<E>): Flowable<T>
= this.compose<T>(provider.bindToLifecycle<T>())

fun <E> Completable.bindUntilEvent(provider: LifecycleProvider<E>, event: E): Completable
= this.compose(provider.bindUntilEvent<Completable>(event))
fun <T, E> Flowable<T>.bindUntilEvent(provider: LifecycleProvider<E>, event: E): Flowable<T>
= this.compose<T>(provider.bindUntilEvent(event))

fun Completable.bindToLifecycle(view: View): Completable
= this.compose(RxLifecycleAndroid.bindView<Completable>(view))
fun <T> Flowable<T>.bindToLifecycle(view: View): Flowable<T>
= this.compose<T>(RxLifecycleAndroid.bindView(view))

fun <T, E> Single<T>.bindToLifecycle(provider: LifecycleProvider<E>): Single<T>
= this.compose(provider.bindToLifecycle<T>())
= this.compose(provider.bindToLifecycle<T>())

fun <T, E> Single<T>.bindUntilEvent(provider: LifecycleProvider<E>, event: E): Single<T>
= this.compose(provider.bindUntilEvent<T>(event))
= this.compose(provider.bindUntilEvent<T>(event))

fun <T> Single<T>.bindToLifecycle(view: View): Single<T>
= this.compose(RxLifecycleAndroid.bindView<T>(view))
= this.compose(RxLifecycleAndroid.bindView<T>(view))

fun <T, E> Maybe<T>.bindToLifecycle(provider: LifecycleProvider<E>): Maybe<T>
= this.compose(provider.bindToLifecycle<T>())

fun <T, E> Maybe<T>.bindUntilEvent(provider: LifecycleProvider<E>, event: E): Maybe<T>
= this.compose(provider.bindUntilEvent<T>(event))

fun <T> Maybe<T>.bindToLifecycle(view: View): Maybe<T>
= this.compose(RxLifecycleAndroid.bindView<T>(view))

fun <E> Completable.bindToLifecycle(provider: LifecycleProvider<E>): Completable
= this.compose(provider.bindToLifecycle<Completable>())

fun <E> Completable.bindUntilEvent(provider: LifecycleProvider<E>, event: E): Completable
= this.compose(provider.bindUntilEvent<Completable>(event))

fun Completable.bindToLifecycle(view: View): Completable
= this.compose(RxLifecycleAndroid.bindView<Completable>(view))

0 comments on commit 9832bd9

Please sign in to comment.