-
|
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? |
Beta Was this translation helpful? Give feedback.
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); |
Beta Was this translation helpful? Give feedback.
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: