/** * Applies this function partially to 4 arguments. * * @param t1 argument 1 * @param t2 argument 2 * @param t3 argument 3 * @param t4 argument 4 * @return a partial application of this function */ default CheckedFunction3<T5, T6, T7, R> apply(T1 t1, T2 t2, T3 t3, T4 t4) { return (T5 t5, T6 t6, T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Applies this function partially to two arguments. * * @param t1 argument 1 * @param t2 argument 2 * @return a partial application of this function */ default CheckedFunction5<T3, T4, T5, T6, T7, R> apply(T1 t1, T2 t2) { return (T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Applies this function partially to one argument. * * @param t1 argument 1 * @return a partial application of this function */ default CheckedFunction6<T2, T3, T4, T5, T6, T7, R> apply(T1 t1) { return (T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Applies this function partially to three arguments. * * @param t1 argument 1 * @param t2 argument 2 * @param t3 argument 3 * @return a partial application of this function */ default CheckedFunction4<T4, T5, T6, T7, R> apply(T1 t1, T2 t2, T3 t3) { return (T4 t4, T5 t5, T6 t6, T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Returns a curried version of this function. * * @return a curried function equivalent to this. */ default Function1<T1, Function1<T2, Function1<T3, Function1<T4, Function1<T5, Function1<T6, CheckedFunction1<T7, R>>>>>>> curried() { return t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Returns a tupled version of this function. * * @return a tupled function equivalent to this. */ default CheckedFunction1<Tuple7<T1, T2, T3, T4, T5, T6, T7>, R> tupled() { return t -> apply(t._1, t._2, t._3, t._4, t._5, t._6, t._7); }
/** * Returns a reversed version of this function. This may be useful in a recursive context. * * @return a reversed function equivalent to this. */ default CheckedFunction7<T7, T6, T5, T4, T3, T2, T1, R> reversed() { return (t7, t6, t5, t4, t3, t2, t1) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Applies this function partially to 5 arguments. * * @param t1 argument 1 * @param t2 argument 2 * @param t3 argument 3 * @param t4 argument 4 * @param t5 argument 5 * @return a partial application of this function */ default CheckedFunction2<T6, T7, R> apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { return (T6 t6, T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Applies this function partially to 6 arguments. * * @param t1 argument 1 * @param t2 argument 2 * @param t3 argument 3 * @param t4 argument 4 * @param t5 argument 5 * @param t6 argument 6 * @return a partial application of this function */ default CheckedFunction1<T7, R> apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { return (T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Returns a composed function that first applies this CheckedFunction7 to the given argument and then applies * {@linkplain CheckedFunction1} {@code after} to the result. * * @param <V> return type of after * @param after the function applied after this * @return a function composed of this and after * @throws NullPointerException if after is null */ default <V> CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, V> andThen(CheckedFunction1<? super R, ? extends V> after) { Objects.requireNonNull(after, "after is null"); return (t1, t2, t3, t4, t5, t6, t7) -> after.apply(apply(t1, t2, t3, t4, t5, t6, t7)); }
/** * Returns an unchecked function that will <em>sneaky throw</em> if an exceptions occurs when applying the function. * * @return a new Function7 that throws a {@code Throwable}. */ default Function7<T1, T2, T3, T4, T5, T6, T7, R> unchecked() { return (t1, t2, t3, t4, t5, t6, t7) -> { try { return apply(t1, t2, t3, t4, t5, t6, t7); } catch(Throwable t) { return sneakyThrow(t); } }; }
/** * Lifts the given {@code partialFunction} into a total function that returns an {@code Try} result. * * @param partialFunction a function that is not defined for all values of the domain (e.g. by throwing) * @param <R> return type * @param <T1> 1st argument * @param <T2> 2nd argument * @param <T3> 3rd argument * @param <T4> 4th argument * @param <T5> 5th argument * @param <T6> 6th argument * @param <T7> 7th argument * @return a function that applies arguments to the given {@code partialFunction} and returns {@code Success(result)} * if the function is defined for the given arguments, and {@code Failure(throwable)} otherwise. */ static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, Try<R>> liftTry(CheckedFunction7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> partialFunction) { return (t1, t2, t3, t4, t5, t6, t7) -> Try.of(() -> partialFunction.apply(t1, t2, t3, t4, t5, t6, t7)); }
/** * Return a composed function that first applies this CheckedFunction7 to the given arguments and in case of throwable * try to get value from {@code recover} function with same arguments and throwable information. * * @param recover the function applied in case of throwable * @return a function composed of this and recover * @throws NullPointerException if recover is null */ default Function7<T1, T2, T3, T4, T5, T6, T7, R> recover(Function<? super Throwable, ? extends Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R>> recover) { Objects.requireNonNull(recover, "recover is null"); return (t1, t2, t3, t4, t5, t6, t7) -> { try { return this.apply(t1, t2, t3, t4, t5, t6, t7); } catch (Throwable throwable) { final Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> func = recover.apply(throwable); Objects.requireNonNull(func, () -> "recover return null for " + throwable.getClass() + ": " + throwable.getMessage()); return func.apply(t1, t2, t3, t4, t5, t6, t7); } }; }
/** * Returns an implication which composes this Property as pre-condition and a given post-condition. * * @param postcondition The postcondition of this implication * @return A new Checkable implication */ public Checkable implies(CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, Boolean> postcondition) { final CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, Condition> implication = (t1, t2, t3, t4, t5, t6, t7) -> { final Condition precondition = predicate.apply(t1, t2, t3, t4, t5, t6, t7); if (precondition.isFalse()) { return Condition.EX_FALSO_QUODLIBET; } else { return new Condition(true, postcondition.apply(t1, t2, t3, t4, t5, t6, t7)); } }; return new Property7<>(name, a1, a2, a3, a4, a5, a6, a7, implication); }
/** * Returns a checkable property that checks values of the 7 variables of this {@code ForAll} quantor. * * @param predicate A 7-ary predicate * @return a new {@code Property7} of 7 variables. */ public Property7<T1, T2, T3, T4, T5, T6, T7> suchThat(CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, Boolean> predicate) { final CheckedFunction7<T1, T2, T3, T4, T5, T6, T7, Condition> proposition = (t1, t2, t3, t4, t5, t6, t7) -> new Condition(true, predicate.apply(t1, t2, t3, t4, t5, t6, t7)); return new Property7<>(name, a1, a2, a3, a4, a5, a6, a7, proposition); } }
/** * Lifts the given {@code partialFunction} into a total function that returns an {@code Option} result. * * @param partialFunction a function that is not defined for all values of the domain (e.g. by throwing) * @param <R> return type * @param <T1> 1st argument * @param <T2> 2nd argument * @param <T3> 3rd argument * @param <T4> 4th argument * @param <T5> 5th argument * @param <T6> 6th argument * @param <T7> 7th argument * @return a function that applies arguments to the given {@code partialFunction} and returns {@code Some(result)} * if the function is defined for the given arguments, and {@code None} otherwise. */ @SuppressWarnings("RedundantTypeArguments") static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, Option<R>> lift(CheckedFunction7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> partialFunction) { return (t1, t2, t3, t4, t5, t6, t7) -> Try.<R>of(() -> partialFunction.apply(t1, t2, t3, t4, t5, t6, t7)).toOption(); }
/** * Wraps the result of a computation that may fail in a {@code Try}. * * @param f A computation that takes seven {@code AutoClosable} resources. * @param <R> Result type of the computation. * @return A new {@code Try} instance. */ @SuppressWarnings("try")/* https://bugs.openjdk.java.net/browse/JDK-8155591 */ public <R> Try<R> of(CheckedFunction7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> f) { return Try.of(() -> { try (T1 t1 = t1Supplier.apply(); T2 t2 = t2Supplier.apply(); T3 t3 = t3Supplier.apply(); T4 t4 = t4Supplier.apply(); T5 t5 = t5Supplier.apply(); T6 t6 = t6Supplier.apply(); T7 t7 = t7Supplier.apply()) { return f.apply(t1, t2, t3, t4, t5, t6, t7); } }); } }
final T7 val7 = Try.of(() -> gen7.apply(random)).recover(x -> { throw genError(7, size, x); }).get(); try { final Condition condition = Try.of(() -> predicate.apply(val1, val2, val3, val4, val5, val6, val7)).recover(x -> { throw predicateError(x); }).get(); if (condition.precondition) { exhausted = false;
/** * Applies this function partially to three arguments. * * @param t1 argument 1 * @param t2 argument 2 * @param t3 argument 3 * @return a partial application of this function */ default CheckedFunction4<T4, T5, T6, T7, R> apply(T1 t1, T2 t2, T3 t3) { return (T4 t4, T5 t5, T6 t6, T7 t7) -> apply(t1, t2, t3, t4, t5, t6, t7); }
/** * Returns a curried version of this function. * * @return a curried function equivalent to this. */ default Function1<T1, Function1<T2, Function1<T3, Function1<T4, Function1<T5, Function1<T6, CheckedFunction1<T7, R>>>>>>> curried() { return t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> t7 -> apply(t1, t2, t3, t4, t5, t6, t7); }