RxPM icon indicating copy to clipboard operation
RxPM copied to clipboard

Type projection for Action

Open lectricas opened this issue 6 years ago • 3 comments
trafficstars

Hey guys. I was trying to user single action as a common sink for multiple buttons:

Observable.just(1).bindTo(pm.someAction)
Observable.just(1.0).bindTo(pm.someAction)

where someAction is val someAction = action<Number>() And I've got the compile time error, which can be fixed by

infix fun <T> Observable<T>.bindTo(action: Action<in T>) { //type projection here
    with(action.pm) {
        [email protected](AndroidSchedulers.mainThread())
            .subscribe(action.consumer)
            .untilUnbind()
    }
}

Have you done it on purpose, so any `action` has strict type parameter?

lectricas avatar Nov 06 '19 22:11 lectricas

Yep, thanks. Will check it.

Jeevuz avatar Nov 13 '19 12:11 Jeevuz

On the other hand there might be some type issues with this approach. Maybe its better to have actions zipped together in pm, than one typed actions

lectricas avatar Nov 13 '19 12:11 lectricas

@lectricas What issues do you mean?

Jeevuz avatar Nov 14 '19 11:11 Jeevuz