More often , while using the smallrye mutiny , you encounter a situation where the called function returns a Uni<T> which as a result if returned as terminal or completion stage results in Uni<Uni<T>> .
Lets take an example (In Kotlin) :
We have a reactive repository
class OrderRepository : PanacheRepository<Order>
Now. you want to persist an order but want to make a result of something else, lets say a view that returns limited information.We call that class OrderView . It returns a very limited properties than the original order.
We are using Mapstruct's mapper, that does not matter for this example, we are just using that to convert our Model to View.
Here is how you will do it.
orderRepository.findById(ObjectId(orderId))
.onItem().ifNull().failWith(CustomException("Order Not Found"))
.onItem().ifNotNull()
.transformToUni { sc ->
//your custom operations
orderRepository.update(order)
}.onItem().transformToUni { ex -> Uni.createFrom().item(orderConverter.convertToView(ex))
}
That is it, our new type Uni<OrderView> is returned whereas on update we had Uni<Order> and if we did not transform that, we would have Uni<Uni<OrderView>>.
I think that was simple. Let us know if you need more information on this.