Recientemente se me ocurrió la idea de crear el siguiente método:
/** Returns a {@link Predicate} which tests whether all its elements match a condition passed as argument. */ private static <T> Predicate<Iterable<T>> allIterableElementsMatch(Predicate<T> elementMatchCondition) { return iterable -> stream(iterable).allMatch(elementMatchCondition); } Entonces decidí declarar Function -field en lugar de declarar un método anterior.
La solución no compilable más cercana que podría proporcionar es esta:
private static final Function<Predicate<?>, Predicate<Iterable<?>>> allIterableElementsMatch = condition -> iterable -> stream(iterable).allMatch(condition); Esto no está compilado (el IDE resalta la condition dentro allMatch(...) ) por el siguiente motivo:
Mis preguntas:
Function -s como en el método que he mostrado?Para el sistema de tipos, ? de Predicate<?> y ? from Predicate<Iterable<?>> son cosas diferentes. Tu puedes hacer:
private static <T> Function<Predicate<T>, Predicate<Iterable<T>>> func() { return condition -> iterable -> StreamSupport.stream(iterable.spliterator(), false).allMatch(condition); }