void (String[] args) { Collection<Integer> result = new LinkedList<>(); Optional<A> _1 = Optional.of(new A()); Optional<B> _2 = Optional.of(new B()); BiFunction<Integer, Integer, Boolean> le = (a, b) -> a <= b; addIfTrue(result, compareIfPresent(_1.map(A::getValue), _2.map(B::getValue), le), 3); System.out.println(result); }