I want to make a lazy evaluation in a list of functions that I defined as follows:
Optional<Output> output = Stream.<Function<Input, Optional<Output>>> of( classA::eval, classB::eval, classC::eval) .map(f -> f.apply(input)) .filter(Optional::isPresent) .map(Optional::get) .findFirst();
where, as you can see, each class (a, b, and c) has a specific Optional<Output> eval(Input in) method. If I try to do
Stream.of(...)....
ignoring the explicit type, it gives
T is not a functional interface
collection error. Do not allow functional interface type for T generic type in .of(T... values)
Is there a faster way to create a stream of these functions? I don't like to explicitly define the of method with Function and its I / O types. Would this work in a more general way?
This question is related to the topic of the following question:
Lambda expression and general method
source share