com.github.tonivade.purefun.Function5 Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun;
/**
* This interface represents a function with a five parameters. There's no equivalence in the JVM.
* The function can throws checked exceptions, but calling {@code apply()} method, the exception is sneaky thrown. So, it
* can be used as a higher order function in {@link java.util.stream.Stream} or {@link java.util.Optional} API.
* @param type of first function parameter
* @param type of second function parameter
* @param type of third function parameter
* @param type of fourth function parameter
* @param type of fifth function parameter
* @param type of return value
*/
@FunctionalInterface
public interface Function5 extends Recoverable {
default R apply(A a, B b, C c, D d, E e) {
try {
return run(a, b, c, d, e);
} catch (Throwable t) {
return sneakyThrow(t);
}
}
R run(A a, B b, C c, D d, E e) throws Throwable;
default Function1>>>> curried() {
return a -> b -> c -> d -> e -> apply(a, b, c, d, e);
}
default Function1, R> tupled() {
return tuple -> apply(tuple.get1(), tuple.get2(), tuple.get3(), tuple.get4(), tuple.get5());
}
default Function5 andThen(Function1 after) {
return (a, b, c, d, e) -> after.apply(apply(a, b, c, d, e));
}
default Function1 compose(Function1 beforeT1, Function1 beforeT2,
Function1 beforeT3, Function1 beforeT4, Function1 beforeT5) {
return value -> apply(beforeT1.apply(value), beforeT2.apply(value),
beforeT3.apply(value), beforeT4.apply(value), beforeT5.apply(value));
}
default Function5 memoized() {
return (a, b, c, d, e) -> new MemoizedFunction<>(tupled()).apply(Tuple.of(a, b, c, d, e));
}
static Function5 cons(R value) {
return (a, b, c, d, e) -> value;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy