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-2019 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.Function;
import java.util.function.Supplier;
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 nullablej.nullable.Nullable;
public interface Apply {
public static O apply(Supplier func) {
return func.get();
}
public static O apply(Ref ref) {
return ref.value();
}
public static O apply(Function func, I input) {
return func.apply(input);
}
public static O apply(BiFunction func, I1 input1, I2 input2) {
return func.apply(input1, input2);
}
public static Func1 apply(BiFunction 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 Supplier $(Function func, Supplier input) {
return Func1.from(func).applyTo(input);
}
public static Function $(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 Supplier $(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 Supplier $(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 Func1 $(Func3 func, Func1 input1, Func1 input2, Func1 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 Supplier $(Func4 func, Supplier input1, Supplier input2, Supplier input3, Supplier