Hi, I’m struggling to think of a good way to comb...
# arrow
v
Hi, I’m struggling to think of a good way to combine
Either
with
Flow
when the flow can emit values before coming across something that should cause failure. For example:
Copy code
fun getNumbersThatAreNotEleven(n: Int): Either<ThatsElevenException, Flow<Int>> = 
  flow {
    for(i in 1..n) {
      if (i == 11) {
        // sacrilege, what do I do here?
      } else {
        emit(i)
      }
    }
  }
a
Not sure if you’ll be able to do it.
flow
is lazily evaluated for each element, so unless you can recognize that something will fail at any point in time, you’d have already emitted the first items
s
fun getNumbersThatAreNotEleven(n: Int): Flow<Either<ThatsElevenException, Int>>
This would work
v
Right, i was afraid it;d be something like the latter
Thanks : )