functionalj.function.Apply Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalj-core Show documentation
Show all versions of functionalj-core Show documentation
The module for FunctionalJ Core.
// ============================================================================
// Copyright (c) 2017-2021 Nawapunth Manusitthipol (NawaMan - http://nawaman.net).
// ----------------------------------------------------------------------------
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ============================================================================
package functionalj.function;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleSupplier;
import java.util.function.DoubleUnaryOperator;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntSupplier;
import java.util.function.IntUnaryOperator;
import java.util.function.LongBinaryOperator;
import java.util.function.LongSupplier;
import java.util.function.LongUnaryOperator;
import java.util.function.Supplier;
import java.util.function.ToDoubleBiFunction;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import functionalj.lens.lenses.DoubleAccess;
import functionalj.lens.lenses.DoubleToDoubleAccessPrimitive;
import functionalj.lens.lenses.DoubleToIntegerAccessPrimitive;
import functionalj.lens.lenses.DoubleToLongAccessPrimitive;
import functionalj.lens.lenses.IntegerAccess;
import functionalj.lens.lenses.IntegerToDoubleAccessPrimitive;
import functionalj.lens.lenses.IntegerToIntegerAccessPrimitive;
import functionalj.lens.lenses.IntegerToLongAccessPrimitive;
import functionalj.lens.lenses.LongAccess;
import functionalj.lens.lenses.LongToDoubleAccessPrimitive;
import functionalj.lens.lenses.LongToIntegerAccessPrimitive;
import functionalj.lens.lenses.LongToLongAccessPrimitive;
import functionalj.list.FuncList;
import functionalj.map.FuncMap;
import functionalj.promise.HasPromise;
import functionalj.promise.Promise;
import functionalj.ref.Ref;
import functionalj.result.Result;
import functionalj.stream.ZipWithOption;
import functionalj.task.Task;
import lombok.val;
import nullablej.nullable.Nullable;
public interface Apply {
public static O apply(Func0 func) {
return func.get();
}
public static O apply(Ref ref) {
return ref.value();
}
public static O apply(Func1 func, I input) {
return func.apply(input);
}
public static O apply(Func2 func, I1 input1, I2 input2) {
return func.apply(input1, input2);
}
public static Func1 apply(Func2 func, I1 input1) {
return input2 -> func.apply(input1, input2);
}
public static O apply(Func3 func, I1 input1, I2 input2, I3 input3) {
return func.apply(input1, input2, input3);
}
public static Func2 apply(Func3 func, I1 input1) {
return func.applyTo(input1);
}
public static Func1 apply(Func3 func, I1 input1, I2 input2) {
return func.applyTo(input1).applyTo(input2);
}
public static O apply(Func4 func, I1 input1, I2 input2, I3 input3, I4 input4) {
return func.apply(input1, input2, input3, input4);
}
public static Func3 apply(Func4 func, I1 input1) {
return func.applyTo(input1);
}
public static Func2 apply(Func4 func, I1 input1, I2 input2) {
return func.applyTo(input1).applyTo(input2);
}
public static Func1 apply(Func4 func, I1 input1, I2 input2, I3 input3) {
return func.applyTo(input1).applyTo(input2).applyTo(input3);
}
public static O apply(Func5 func, I1 input1, I2 input2, I3 input3, I4 input4, I5 input5) {
return func.apply(input1, input2, input3, input4, input5);
}
public static Func4 apply(Func5 func, I1 input1) {
return func.applyTo(input1);
}
public static Func3 apply(Func5 func, I1 input1, I2 input2) {
return func.applyTo(input1).applyTo(input2);
}
public static Func2 apply(Func5 func, I1 input1, I2 input2, I3 input3) {
return func.applyTo(input1).applyTo(input2).applyTo(input3);
}
public static Func1 apply(Func5 func, I1 input1, I2 input2, I3 input3, I4 input4) {
return func.applyTo(input1).applyTo(input2).applyTo(input3).applyTo(input4);
}
public static O apply(Func6 func, I1 input1, I2 input2, I3 input3, I4 input4, I5 input5, I6 input6) {
return func.apply(input1, input2, input3, input4, input5, input6);
}
public static Func5 apply(Func6 func, I1 input1) {
return func.applyTo(input1);
}
public static Func4 apply(Func6 func, I1 input1, I2 input2) {
return func.applyTo(input1).applyTo(input2);
}
public static Func3 apply(Func6 func, I1 input1, I2 input2, I3 input3) {
return func.applyTo(input1).applyTo(input2).applyTo(input3);
}
public static Func2 apply(Func6 func, I1 input1, I2 input2, I3 input3, I4 input4) {
return func.applyTo(input1).applyTo(input2).applyTo(input3).applyTo(input4);
}
public static Func1 apply(Func6 func, I1 input1, I2 input2, I3 input3, I4 input4, I5 input5) {
return func.applyTo(input1).applyTo(input2).applyTo(input3).applyTo(input4).applyTo(input5);
}
//== $ ==
public static O $(Supplier func) {
return func.get();
}
public static O $(Ref ref) {
return ref.value();
}
public static O $(Function func, I input) {
return func.apply(input);
}
public static Result $(Function func, Result input) {
return Func1.from(func).applyTo(input);
}
public static Optional $(Function func, Optional input) {
return Func1.from(func).applyTo(input);
}
public static Nullable $(Function func, Nullable input) {
return Func1.from(func).applyTo(input);
}
public static FuncList $(Function func, List input) {
return Func1.from(func).applyTo(input);
}
public static FuncMap $(Function func, Map input) {
return Func1.from(func).applyTo(input);
}
public static Func0 $(Function func, Supplier input) {
return Func1.from(func).applyTo(input);
}
public static Func1 $(Function func, Function input) {
return Func1.from(func).applyTo(input);
}
public static Promise $(Function func, HasPromise input) {
return Func1.from(func).applyTo(input);
}
public static Task $(Function func, Task input) {
return Func1.from(func).applyTo(input);
}
public static O $(BiFunction func, I1 input1, I2 input2) {
return func.apply(input1, input2);
}
public static Func1 $(BiFunction func, I1 input1) {
return input2 -> func.apply(input1, input2);
}
public static Result $(BiFunction func, Result input1, Result input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static Optional $(BiFunction func, Optional input1, Optional input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static Nullable $(BiFunction func, Nullable input1, Nullable input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static FuncList $(BiFunction func, FuncList input1, FuncList input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static FuncList $(BiFunction func, FuncList input1, FuncList input2, ZipWithOption option) {
return Func2.from(func).applyTo(input1, input2, option);
}
public static FuncMap $(BiFunction func, FuncMap input1, FuncMap input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static FuncMap $(BiFunction func, FuncMap input1, FuncMap input2, ZipWithOption option) {
return Func2.from(func).applyTo(input1, input2, option);
}
public static Func0 $(BiFunction func, Supplier input1, Supplier input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static Promise $(BiFunction func, HasPromise input1, HasPromise input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static Task $(BiFunction func, Task input1, Task input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static Func1 $(BiFunction func, Func1 input1, Func1 input2) {
return Func2.from(func).applyTo(input1, input2);
}
public static O $(Func3 func, I1 input1, I2 input2, I3 input3) {
return func.apply(input1, input2, input3);
}
public static Func2 $(Func3 func, I1 input1) {
return func.applyTo(input1);
}
public static Func1 $(Func3 func, I1 input1, I2 input2) {
return func.applyTo(input1).applyTo(input2);
}
public static Result $(Func3 func, Result input1, Result input2, Result input3) {
return func.applyTo(input1, input2, input3);
}
public static Optional $(Func3 func, Optional input1, Optional input2, Optional input3) {
return func.applyTo(input1, input2, input3);
}
public static Nullable $(Func3 func, Nullable input1, Nullable input2, Nullable input3) {
return func.applyTo(input1, input2, input3);
}
public static Func0 $(Func3 func, Supplier input1, Supplier input2, Supplier input3) {
return func.applyTo(input1, input2, input3);
}
public static Promise $(Func3 func, HasPromise input1, HasPromise input2, HasPromise input3) {
return func.applyTo(input1, input2, input3);
}
public static Task $(Func3 func, Task input1, Task input2, Task input3) {
return func.applyTo(input1, input2, input3);
}
public static O $(Func4 func, I1 input1, I2 input2, I3 input3, I4 input4) {
return func.apply(input1, input2, input3, input4);
}
public static Func3 $(Func4 func, I1 input1) {
return func.applyTo(input1);
}
public static Func2 $(Func4 func, I1 input1, I2 input2) {
return func.applyTo(input1).applyTo(input2);
}
public static Func1 $(Func4 func, I1 input1, I2 input2, I3 input3) {
return func.applyTo(input1).applyTo(input2).applyTo(input3);
}
public static Result $(Func4 func, Result input1, Result input2, Result input3, Result input4) {
return func.applyTo(input1, input2, input3, input4);
}
public static Optional $(Func4 func, Optional input1, Optional input2, Optional input3, Optional input4) {
return func.applyTo(input1, input2, input3, input4);
}
public static Nullable $(Func4 func, Nullable input1, Nullable input2, Nullable input3, Nullable input4) {
return func.applyTo(input1, input2, input3, input4);
}
public static Func0 $(Func4 func, Supplier input1, Supplier input2, Supplier input3, Supplier input4) {
return func.applyTo(input1, input2, input3, input4);
}
public static Promise $(Func4 func, HasPromise input1, HasPromise input2, HasPromise