Skip to content

Instantly share code, notes, and snippets.

@Francesco-itembase
Last active May 26, 2020 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Francesco-itembase/67d88812f194a054a34f3b578e86b8be to your computer and use it in GitHub Desktop.
Save Francesco-itembase/67d88812f194a054a34f3b578e86b8be to your computer and use it in GitHub Desktop.
// 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