artem-zinnatullin / RxUi

Implementation of pure functional concept of talking to Android View layer in a Reactive way
https://artemzin.com/blog/rxui-talking-to-android-view-layer-in-a-reactive-way/
MIT License
261 stars 22 forks source link

Kotlin 1.1 bound callable references #29

Open drampelt opened 7 years ago

drampelt commented 7 years ago

Since Kotlin 1.1 added bound callable references, binding observables to UI actions can be simplified significantly, mainly using normal functions as actions instead of vals with the type Func1<Observable<T>, Subscription>.

Quick example:


interface MainView {
    ...
    fun signInSuccess(success: Success)
    ...
}

class Presenter {
    ...
    signInResult
        .filter { it is Success }
        .map { it as Success }
        .bind(view::signInSuccess)
    ...
}

fun <T> Observable<T>.bind(action: (T) -> Unit): Subscription =
    observeOn(AndroidSchedulers.mainThread()).subscribe(action)

What are your thoughts on this?

artem-zinnatullin commented 7 years ago

Yes, that is great option! Want to submit a PR?