raulraja
09/10/2019, 1:58 PMBob Glamm
09/10/2019, 2:01 PMBob Glamm
09/10/2019, 2:05 PMraulraja
09/10/2019, 4:14 PMraulraja
09/10/2019, 4:14 PMraulraja
09/10/2019, 4:15 PMraulraja
09/10/2019, 4:17 PMraulraja
09/10/2019, 4:17 PMlaimiux
09/10/2019, 9:48 PMval account = getProcessedAccount().bind()
raulraja
09/10/2019, 10:02 PMbind
gets translated to flatmap. For example when binding is over a non deterministic monad like List this is equivalent:
listOf(1, 2, 3).flatMap { n -> listOf(n + 1) }
ListK.fx {
val n = listOf(1, 2, 3).bind()
n + 1
}
raulraja
09/10/2019, 10:03 PMraulraja
09/10/2019, 10:04 PMfx {
val (a) = listOf(1, 2)
val (b) = listOf(true, false)
a toT b
}
vs
fx {
val (b) = listOf(true, false)
listOf(1, 2) toT b
}
raulraja
09/10/2019, 10:05 PMa
by it’s bound value you would get different results that if you bind over a
.raulraja
09/10/2019, 10:07 PMraulraja
09/10/2019, 10:08 PMlaimiux
09/10/2019, 10:27 PMraulraja
09/10/2019, 11:31 PMraulraja
09/10/2019, 11:32 PMlaimiux
09/11/2019, 5:10 PMraulraja
09/11/2019, 5:39 PMsimon.vergauwen
09/11/2019, 6:02 PMsimon.vergauwen
09/11/2019, 6:02 PMsimon.vergauwen
09/11/2019, 6:02 PMlaimiux
09/11/2019, 6:03 PMsimon.vergauwen
09/11/2019, 6:04 PMsealed
model to the UI and the domain layer part is what you’d do for any other FP appsimon.vergauwen
09/11/2019, 6:06 PMsimon.vergauwen
09/11/2019, 6:08 PMtypealias Refresh = Unit
data class Item(val id: String)
interface HomeScreen {
suspend fun render(home: HomeViewModel)
fun refresh(): Observable<Refresh>
fun itemSelected(): Observable<Item>
...
}
simon.vergauwen
09/11/2019, 6:22 PMlaimiux
09/11/2019, 9:35 PMlaimiux
09/11/2019, 9:36 PMsimon.vergauwen
09/11/2019, 9:48 PMsimon.vergauwen
09/11/2019, 9:55 PMonError
or onComplete
, and you can hold a BehaviorRelay
which caches it’s last value in your Fragment. Since Fragments are retained over config chance and only their views are destroyed you can simply use the `BehaviorRelay`’s last cached value to redraw your views.simon.vergauwen
09/11/2019, 9:59 PMlaimiux
09/11/2019, 11:21 PMRxRelays
for retaining last emitted state. Though, for events we moved to a render model concept -> ButtonRenderModel(val text: String, val onClick: () -> Unit)
so the UI is not aware of event/message passing solution.laimiux
09/11/2019, 11:22 PMsimon.vergauwen
09/11/2019, 11:49 PMfun <A> Single<A>.asIO(): IO<A> = IO.concurrent().cancelable<A> { cb ->
val disposable = subscribe({ a -> cb(Right(a)) }, { e -> cb(Left(e)) })
IO { disposable.dispose() }
}.fix()
fun <A> IOOf<A>.asSingle(): Single<A> = Single.create { emitter ->
val disposable = fix().unsafeRunAsyncCancellable { either ->
either.fold({ e -> emitter.tryOnError(e) }, { a -> emitter.onSuccess(a) })
}
emitter.setCancellable { disposable.invoke() }
}
simon.vergauwen
09/11/2019, 11:52 PMIO
has some more complex concurrency constructs common in FP such as bracketCase
, parTraverse
& co and it has a pure API. RxJava takes a slightly different approach with an impure API, it currently also has some operators that Arrow doesn’t have yet so that goes both ways atm.simon.vergauwen
09/11/2019, 11:56 PMButtonRenderModel
. However that is still has an impure API, changing that to ButtonRenderModel(val text: String, val onClick: suspend () -> Unit)
makes it pure and you can easily integrate it in your Arrow Fx program.laimiux
09/12/2019, 12:24 AMsuspend
in this place because the onClick
callback is used within Android framework buttonView.setOnClickListener { renderModel.onClick() }
laimiux
09/12/2019, 12:26 AMsimon.vergauwen
09/12/2019, 7:48 AMretry
and co operators we’d probably introduce a Schedule
data type which represents how you want to retry. https://github.com/zio/zio/blob/master/docs/datatypes/schedule.md That would allow you to define your retry mechanisms separately and make them compose. Beside that IO
surpasses Single
operator wise, but I’d have to put the 2 next to each-other.simon.vergauwen
09/12/2019, 7:49 AMlaimiux
09/12/2019, 6:32 PMzio
(not that I’m very knowledgeable on it).