// acquire data source | |
Flux<Integer> dataSource = Flux.just(1, 2, 3, 4, 5, 6); | |
// define pipeline of operations | |
Flux<Integer> pipeline = dataSource | |
.filter(num -> num % 2 == 0) | |
.map(num -> num + 1); | |
// execute pipeline | |
pipeline.subscribe(); | |
// ------------------------------------------------------------ | |
Flux<T> dataSource = // get the data source from wherever (e.g. network request body, DB call, method call) | |
Flux<T> pipeline = dataSource | |
.operation1(x -> /* perform work on x */) | |
.operation2(y -> /* perform work on y */) | |
.operation3(z -> /* perform work on z */); | |
// ------------------------------------------------------------ | |
Flux<T> dataSource = // get the data source from wherever | |
Flux<T> pipeline = dataSource | |
.operation1(x -> /* perform work on x */) | |
.operation2(y -> /* perform work on y */) | |
.operation3(z -> /* perform work on z */); | |
/* | |
* this will actually execute our pipeline | |
* as there's at least one subscriber | |
* interested in it | |
*/ | |
pipeline.subscribe(); | |
// ------------------------------------------------------------ | |
// this is our reactive collection of type UserEntity | |
Mono<UserEntity> currentUser = loginService.getCurrentLoggedUser(); | |
// let’s operate on our reactive collection | |
Mono<Boolean> isUserAllowed = currentUser | |
.map(UserEntityUtils::convertEntityToModel) | |
.filter(UserModelUtils::isUserAdmin) | |
.switchIfEmpty(Mono.defer(() -> false)) | |
.flatmap(userModel -> true); | |
return isUserAllowed; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment