Mark Fisher
01/22/2020, 3:02 PMclass ArrowRxTests {
@Test
fun `comprehension with arrow and rx`() {
val x = SingleK.fx {
val (count) = getCountSingle // this is an async call using a SingleK.monadDefer
val newCount = increment(count) // this is an async call returning Single<Int>.... how do i use it here?
newCount
}.value()
assertThat(x.blockingGet()).isEqualTo(2)
}
private fun getCount() = 1
private fun <F> getCountAsync(MS: MonadDefer<F>) = MS.later { getCount() }
private val getCountSingle: SingleKOf<Int> = getCountAsync(SingleK.monadDefer())
private fun increment(i: Int): Single<Int> = Single.just(i + 1)
}
This works if increment just returns an int, but how do I use increment() in the comprehension when it already returns a Single?
I want to somehow keep the flow of the code inside SingleK.fx {} but using functions that return Rx typessimon.vergauwen
01/22/2020, 3:07 PMgetCountSingle using operator fun component1() or destructuring.simon.vergauwen
01/22/2020, 3:07 PMoperator fun not() or fun bind().
So val (count) = getCountSingle is the same as val count = getCountSingle.bind() or val count = !getCountSingle.simon.vergauwen
01/22/2020, 3:08 PMincrement .simon.vergauwen
01/22/2020, 3:08 PMval x = SingleK.fx {
val count = !getCountSingle
val newCount = !increment(count)
newCount
}.value()Mark Fisher
01/22/2020, 3:09 PMsimon.vergauwen
01/22/2020, 3:09 PMfxsimon.vergauwen
01/22/2020, 3:10 PMreceiver AsyncSyntax<ForSingle> which should be the scope of this within fx.Mark Fisher
01/22/2020, 3:10 PMJannis
01/22/2020, 3:10 PMSingle -> SingleK like k() ? because that is what you need first^^simon.vergauwen
01/22/2020, 3:10 PMSingleK.simon.vergauwen
01/22/2020, 3:11 PMSyntax classes for wrappers such as arrow-fx-rx and arrow-fx-reactorsimon.vergauwen
01/22/2020, 3:11 PMMark Fisher
01/22/2020, 3:12 PM!increment(count).k() workedsimon.vergauwen
01/22/2020, 3:12 PMKind<ForSingleK, A> and not for Single<A> directly.simon.vergauwen
01/22/2020, 3:13 PMMark Fisher
01/22/2020, 3:13 PMMark Fisher
01/22/2020, 3:14 PMsimon.vergauwen
01/22/2020, 3:16 PM