com.github.morinb.func.Function5 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of func Show documentation
Show all versions of func Show documentation
Simple Functional interfaces for Java
/*
* Copyright 2024 Baptiste MORIN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.morinb.func;
import java.util.Objects;
/**
* Represents a function that accepts five arguments and produces a result.
* This is a functional interface whose functional method is {@link #apply(Object, Object, Object, Object, Object)}.
*
* @param the type of the first input to the function
* @param the type of the second input to the function
* @param the type of the third input to the function
* @param the type of the fourth input to the function
* @param the type of the fifth input to the function
* @param the type of the result of the function
*/
@FunctionalInterface
public interface Function5
{
/**
* Applies this function to the given arguments.
*
* @param param1 the first input parameter
* @param param2 the second input parameter
* @param param3 the third input parameter
* @param param4 the fourth input parameter
* @param param5 the fifth input parameter
* @return the result of applying this function to the given arguments
*/
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5);
/**
* Returns a new function that applies the provided function after applying this function.
*
* @param the type of the result of the after function
* @param after the function to apply after this function
* @return the composed function
* @throws NullPointerException if the provided function is null
*/
default Function5 andThen(final Function1 super R, ? extends V> after)
{
Objects.requireNonNull(after, "after is null");
return (T1 param1, T2 param2, T3 param3, T4 param4, T5 param5) -> after.apply(apply(param1, param2, param3, param4, param5));
}
/**
* Returns a curried version of the function.
*
* @return a curried version of the function
*/
default Function1>>>> curried()
{
return param1 -> param2 -> param3 -> param4 -> param5 -> apply(param1, param2, param3, param4, param5);
}
}