https://kotlinlang.org logo
#arrow
Title
# arrow
r

raulraja

01/30/2018, 8:10 PM
you can use monad comprehensions to express those flatMap unnested. It would look something like this (untested):
Copy code
ObservableKW.monadError().bindingCatch {
  val absValue = plainObservable.k().bind()
  val transformedValue = Observables.fromIterable(List<Int>(9) { it * absValue }).k().bind()
  vat afterTriedInt = tryObservable.k().bind().fold({ throw CustomEx }, { it })
  val result = Observables.fromIterable(List<Int>(9) { it * afterTriedInt }).k().bind()
  yields(result)
}.ev()