Hi Folks!
i am not sure this should belong to arrow or rxjava.
Anyway, I have an idea to a function asSequence(), my idea is like this. Btw, i am speaking in android world, but this should be can implemented in another platform. Supposed, we have an view which is an Activity, that calling multiple function in certain callback.
class FooActivity() : AppCompatActivity(), BasePresenter<FooPresenter, FooPresenter.View>, FooPresenter.FooView {
@Inject
lateinit var presenter: FooPresenter
override fun onCreate(/* args */) {
presenter.beginWith(doSomeWork(1)).then(doGreatWork(2))
}
}
ini onCreate callback we call a functions from presenter
i am trying to by using asSequence()
we can solve this by using rxjava flatmap. but, i believe by using asSequence() we can saving more code. That second call waiting until first done (onComplete or onErrror)
Below is sample code for presenter.
class FooPresenter : BasePresenter<FooPresenter, FooPresenter.View> {
fun doSomeWork(id: Int) {
// todo
view.someWorkSuccess()
}
fun doGreatWork(id: Int) {
// todo
view.greatWorkSuccess()
}
interface View : BaseView {
view.someWorkSuccess()
view.greatWorkSuccess()
}
}
what do you guys think about this? thanks
@radityagumay a few things in mind:
greatWorkSuccess or any of those functions you'd have to provide it in a synchronous way as well.arrow-stream which will power arrow-android, an integration layer to handle the lifecycle callbacks in Contexts in a purely functional way.Stream<F, A> in arrow-stream will allow F to be any effect type which at the moment those are Deferred from Kotlin Coroutines, Observable, Flowable from RxJava and IO from arrow.effects. This approach to streaming is a much better way to describe effects in a stream and can be adapted to any existing frameworks since the user may already have in place such as Rx or just Coroutines. Really any data time that can provide an instance for the Effect type class.While I think what you describe is a good idea in principle I'm not sure Sequence is the right abstraction or data type for it and this kind of issue is what we are wanting to address in arrow-android and arrow-stream. @franciscodr is taking the lead with arrow-stream and I believe many of us including @pakoito @JorgeCastilloPrz @nomisRev and others are interested in a pure functional solution for handling Android's inheritance based lifecycle callbacks.
@raulraja Ya, i means is a stream abstraction.
So, in implementation detail we have two constructs. that using RxJava subscribe or / and coroutine suspended functions.
presenter.beginWith(doSomeWork(1)).then(doGreatWork(2)).subscribe { success ->
// consume the data
}
val data = presenter.beginWith(doSomeWork(1)).then(doGreatWork(2)) ->
// doSomeWork and doGreatWork are suspended functions
Most helpful comment
@radityagumay a few things in mind:
greatWorkSuccessor any of those functions you'd have to provide it in a synchronous way as well.arrow-streamwhich will powerarrow-android, an integration layer to handle the lifecycle callbacks in Contexts in a purely functional way.Stream<F, A>inarrow-streamwill allowFto be any effect type which at the moment those areDeferredfrom Kotlin Coroutines,Observable,Flowablefrom RxJava andIOfromarrow.effects. This approach to streaming is a much better way to describe effects in a stream and can be adapted to any existing frameworks since the user may already have in place such as Rx or just Coroutines. Really any data time that can provide an instance for theEffecttype class.While I think what you describe is a good idea in principle I'm not sure
Sequenceis the right abstraction or data type for it and this kind of issue is what we are wanting to address inarrow-androidandarrow-stream. @franciscodr is taking the lead witharrow-streamand I believe many of us including @pakoito @JorgeCastilloPrz @nomisRev and others are interested in a pure functional solution for handling Android's inheritance based lifecycle callbacks.