https://kotlinlang.org logo
Title
r

Robert Wijas

07/28/2022, 4:14 PM
I have a flow that emits when value changes. That value is mapped to a value with optional expiration date. I want to emit recalculated value when the last value expires. My current solution is recursive and I don’t really like that.
fun myFlow(): Flow<B> =
  valueFlow()
    .map { B(it) } // B is the type with expiration date
    .flatMapLatest { value ->
      flow {
        emit(value)
        value.timeToExpiration?.let {
          delay(it)
          emitAll(myFlow()) // !recursion
        }
      }
    }
Any hints how to remove recursion? Thx.