/** * Test for equivalence * null eqv to absent, embedded value equivalency, non-values converted to values before testing *. * <pre> * {@code * * Stream.of(Maybe.of(2)) * .filter(eqv(Maybe.of(2))) * .forEach(System.out::println); * * //Maybe[2] * * Stream.of(2) * .filter(eqv(Maybe.of(2))) * .forEach(System.out::println); * * //2 (passes filter as equivalent to Maybe[2]) * }</pre> * * @param value * @return */ public static <V> Predicate<Value<? super V>> eqv(final Value<? super V> value) { return test -> test == null ? value == null ? true : !value.toMaybe() .isPresent() : test.toMaybe() .equals(value.toMaybe()); }
/** * <pre> * {@code * import static cyclops2.function.Predicates.valuePresent; * * Seq.of(Maybe.ofNullable(null),Maybe.just(1),null) * .filter(valuePresent()); * * //Seq[Maybe[1]] * } * </pre> * @return A Predicate that checks if it's input is a cyclops2-react Value (which also contains a present value) */ public static <T> Predicate<T> valuePresent() { return t -> t instanceof Value ? ((Value) t).toMaybe() .isPresent() : false; }
/** * Test for equivalence * null eqv to absent, embedded value equivalency, non-values converted to values before testing *. * <pre> * {@code * * Stream.of(Maybe.of(2)) * .filter(eqv(Maybe.of(2))) * .forEach(System.out::println); * * //Maybe[2] * * Stream.of(2) * .filter(eqv(Maybe.of(2))) * .forEach(System.out::println); * * //2 (passes filter as equivalent to Maybe[2]) * }</pre> * * @param value * @return */ public static <V> Predicate<Value<? super V>> eqv(final Value<? super V> value) { return test -> test == null ? value == null ? true : !value.toMaybe() .isPresent() : test.toMaybe() .equals(value.toMaybe()); }
/** * <pre> * {@code * import static cyclops2.function.Predicates.valuePresent; * * Seq.of(Maybe.ofNullable(null),Maybe.just(1),null) * .filter(valuePresent()); * * //Seq[Maybe[1]] * } * </pre> * @return A Predicate that checks if it's input is a cyclops2-react Value (which also contains a present value) */ public static <T> Predicate<T> valuePresent() { return t -> t instanceof Value ? ((Value) t).toMaybe() .isPresent() : false; }