tschuchort
06/03/2018, 8:58 PMfun <T> foo(t: T, setProp: T.(Int) -> Unit, getProp: T.() -> Int) = t.apply { setProp(getProp() + 1) }
but what I want to do is:
fun <T> foo(t: T, prop: Property<T,Int>) = t.apply { prop += 1 }
diesieben07
06/03/2018, 9:06 PMval prop: K(Mutable)Property1<MyClass, Int> = MyClass::property
should do what you want.tschuchort
06/03/2018, 9:12 PMprop.set(t, prop.get(t) + 1)
then which defeats the purpose of making the syntax nicer.tschuchort
06/03/2018, 9:13 PMdiesieben07
06/03/2018, 9:19 PMoperator fun <R> KProperty0<R>.getValue(receiver: Nothing?, p: KProperty<*>) = get()
operator fun <R> KMutableProperty0<R>.setValue(receiver: Nothing?, p: KProperty<*>, value: R) = set(value)
fun foo(property: KMutableProperty0<Int>) {
val prop by property
}
diesieben07
06/03/2018, 9:21 PMKProperty1<T, R>
and a receiver value T
into a KProperty0<R>
yet.tschuchort
06/03/2018, 9:31 PMdiesieben07
06/03/2018, 9:32 PMKProperty1
, makes it easier for the caller of your functiontschuchort
06/03/2018, 9:38 PMdiesieben07
06/03/2018, 9:39 PMtschuchort
06/03/2018, 9:40 PMtschuchort
06/03/2018, 9:41 PMdiesieben07
06/03/2018, 9:43 PMKProperty
would be cleaner overall, but I can see why you don't want to do it.tschuchort
06/03/2018, 9:45 PMfun <S : State, V : View<S>, T> handlePagination(loadNextPage: () -> Single<List<T>>,
endReachedSignal: Observable<*>,
getCurrentState: () -> S,
getList: S.() -> List<T>,
setList: S.(List<T>) -> Any?,
setLoading: S.(Boolean) -> Any?,
showPagingFailed: V.() -> Any?)
: Observable<ProgramUpdate<S, V>> {
fun load() = just(StateChange<S, V> { setLoading(true) })
.then(loadNextPage().retryDelayed(delay = 1000, times = 5)
.map<ProgramUpdate<S,V>> { nextPageItems ->
StateChange {
setList(getList() + nextPageItems)
}
}
.onErrorReturn {
Timber.e(it)
ViewAction(showPagingFailed)
}
)
.then(StateChange<S, V> { setLoading(false) })
fun initList() =
if (getCurrentState().getList().isEmpty())
load()
else
never()
return merge(endReachedSignal.dropMap { load() }, initList())
}
so you can see why I want to make them simpler