I am trying to refactor some code to return a list of optionals instead of an optional.
I have the following list in my class
private final List<Mapper<? extends Message>> mappers;
There is a private method that creates features for these mappers and returns a list of message
private List<Message> mapToFeature() {
mappers.stream()
.map(mapper -> mapper.createFeature())
.collect(Optionals.toList());
}
The Mapper interface looks like this:
public interface Mapper<T extends Message> {
Optional<T> createFeature();
}
The Optionals.toList() method returns a Collector to filter present optionals into a List.
I want to change the interface (and all the corresponding classes) to return a list of optionals
public interface Mapper<T extends Message> {
List<Optional<T>> createFeature();
}
I do not have a method in the Optionals util to filter present options from multiple lists. How would I be able to do the same without making any changes to the util class?