Repository navigation
|
Still getting my feet wet. I have code that needs to "carry forward" an interim result. Roughly like that: Uni<CustomerProfile> uniCustomer = CustomerStore(someId);
uniCustomer.map(myCustomer -> PromoStore.getPromos())
.subscribe().with(promo -> sendPromo(myCustomer,promo), this::handleError);Obviously that doesn't work. List<CustomerProfile> profiles = new ArrayList<>();
Uni<CustomerProfile> uniCustomer = CustomerStore(someId);
uniCustomer.map(myCustomer -> {
profiles.add(myCustomer);
return PromoStore.getPromos();
})
.subscribe().with(promo -> sendPromo(profiles.get(0),promo), this::handleError);But that doesn't feel right. What could I do instead? |
Answered by
jponge
Sep 17, 2025
Replies: 1 comment
|
One way to solve it is to rely on some external container data type as you did. Another way is to create a data class to hold the values for the call to There are also times where you can use a nested Uni.createFrom().item(123)
.flatMap(base -> Uni.createFrom().item(List.of(base, base + 1, base + 2))
.map(list -> Uni.createFrom().item(base + " -> " + list)))
.subscribe().with(System.out::println); |
0 replies
Answer selected by
Stwissel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One way to solve it is to rely on some external container data type as you did.
Another way is to create a data class to hold the values for the call to
.getPromos()andmyCustomer, so in the next step you have access to both (e.g.,MyClass(List<CustomerProfiles>, CustomerProfile)).There are also times where you can use a nested
flatMap/concatMap/transformToUniso you can keep a value in scope, as in: