'Combine nexted Mono in Project Reactor Java

Using the https://projectreactor.io/ with Micronaut application. Quite now sure how to combine nexted Mono.

    public Mono<SubCategoryModel> create(ObjectId id, SubCategoryModel model) {
        return iCategoryRepository.findById(id).map(item -> {
            Category category = item;
            category.setSubCategory(List.of(new CategorySubCategory(model.name(), model.description())));
            return iCategoryRepository.save(category)
                    .map(subCategory -> new SubCategoryModel(subCategory.getId().toString(), subCategory.getName(), subCategory.getDescription()))
                    .block();
        });
}

From the first map function I need to pass the value to the second Category category = item;

Here I am using block(), but I don't want to use block

Signature of save and findAll

    <S extends E> Mono<S> save(@NonNull @Valid @NotNull S entity);
    Mono<E> findById(@NonNull @NotNull ID id);

How can I return Mono without block ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source