I have a flow that emits when value changes. That ...
# flow
r
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.
Copy code
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.