创建保持原始顺序的单声道数组对象

Create Mono Array Object with keeping original ordering

我需要实现 returns Mono< Array< ProcessedObject>> 的功能。作为参数,它获取对象列表并使用 returns Mono 函数处理它们。函数需要保持原始顺序,这意味着返回列表中的第一个元素必须从参数列表中的第一个元素创建。到目前为止,我有以下解决方案,但它没有保持所需的顺序。甚至可以使用 Flux 吗?

       private fun createItems(objects: List<Someobjects>): Mono<Array<ProcessedObject>> {
         return Flux.fromIterable(objects)
           .flatMap {
             processObject(it)
           }.collectList().map { it.toTypedArray() }
}

编辑:澄清一点 processObject returns Mono< ProcessedObject>

您可以尝试使用 concatMap 而不是 flatMap

这是 Docu https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Flux.html#concatMap-java.util.function.Function-

的 link
private fun createItems(objects: List<Someobjects>): Mono<Array<ProcessedObject> {
         return Flux.fromIterable(objects)
           .concatMap {
             processObject(it)
           }.collectList().map { it.toTypedArray() }
}

flatMap和concatMap的区别在于后者保留了原来的顺序。