How do I convert this below if/else statement to java stream pipeline?
I have an Optional<> and if That is present then I am making a database call which returns a list and I want to stream over that list and if certain condition is met I want to perform an operation and if not I want to perform some other operation
if(returnOptional().isPresent) {
List<Object> list = db.findAllById(id);
if(list.stream().anyMatch(x -> /*predicate*/)){
//perform function
} else {
//perform function
}
}
Partial Solution :
returnOptional()
.map(obj -> {
List<Object> list = db.call();
return list.stream()
.filter(/*Predicate*/)
.findAny().map(object -> /*function*/)
.orElse(null);
}).orElseGet(() -> /*function*/);