简体   繁体   中英

Zip mono/flux with another that depends on the one I own

I want to zip two monos/fluxes, but the second one (the one I'll zip) is dependand from the first that I already own.
For example:

//...

    fun addGroup(
        input: GroupInput
    ): Mono<Group> = Mono.just(Group(title = input.title, description = input.description))
        .flatMap { g -> groupsRepository.save(g) } // Gives me back the new db ID
        .zipWith(Mono.just(GroupMember(g.id /* <-- ??*/, input.ownerId, true)))
        //...

// ...

Is it possible?

I would say no. You can only zip things that can run in parallel.

you could use map or flatmap in this case, is there any reason you need to use Zip?

No, your code cannot even compile because variable g belongs to the lambda inside the flatMap() call. zipWith() is not intended for this use case, use map() or flatMap()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM