Kotlin 协程和 Arrow 是避免嵌套平面图的好方法,在 Kotlin 中引入了单子推导。然而 Kotlin 的Flow
类型仍然依赖于声明式平面映射,所以我们混合了直接和声明式风格:
override suspend fun findAll(page: Pageable): Either<BusinessException, Flow<PageElement<ClientOut>>> = either {
val count = clientRepository.count().awaitSingle().bind()
return clientRepository.findByIdNotNull(page).asFlow()
.flatMapMerge { client ->
flow { emit(mapDetailedClientOut(client)) }
}
}
val count
一直被束缚在either {...}
领悟之内。但是,似乎没有办法对 做同样的事情Flow
,迫使我们嵌套一个flatmapMerge()
.
有没有办法做到这一点,还是计划在不久的将来以某种方式包含在内?