functionalj.function.FuncUnit3 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 static java.util.Objects.requireNonNull;
import functionalj.functions.ThrowFuncs;
import functionalj.promise.HasPromise;
import functionalj.promise.Promise;
import functionalj.tuple.Tuple3;
import lombok.val;
@FunctionalInterface
public interface FuncUnit3 {
public static FuncUnit3 of(FuncUnit3 consumer) {
return consumer;
}
public static FuncUnit3 from(FuncUnit3 consumer) {
return consumer::accept;
}
public void acceptUnsafe(INPUT1 input1, INPUT2 input2, INPUT3 input3) throws Exception;
public default void accept(INPUT1 input1, INPUT2 input2, INPUT3 input3) {
try {
acceptUnsafe(input1, input2, input3);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw ThrowFuncs.exceptionTransformer.value().apply(e);
}
}
public default void acceptCarelessly(INPUT1 input1, INPUT2 input2, INPUT3 input3) {
try {
acceptUnsafe(input1, input2, input3);
} catch (Exception e) {
}
}
public default FuncUnit3 then(FuncUnit0 after) {
requireNonNull(after);
return (input1, input2, input3) -> {
acceptUnsafe(input1, input2, input3);
after.runUnsafe();
};
}
public default FuncUnit3 then(FuncUnit3 super INPUT1, ? super INPUT2, ? super INPUT3> after) {
requireNonNull(after);
return (input1, input2, input3) -> {
acceptUnsafe(input1, input2, input3);
after.acceptUnsafe(input1, input2, input3);
};
}
public default Func3 thenReturnNull() {
return thenReturn(null);
}
public default Func3 thenReturn(T value) {
return (input1, input2, input3) -> {
acceptUnsafe(input1, input2, input3);
return value;
};
}
public default Func3 thenGet(Func0 supplier) {
requireNonNull(supplier);
return (input1, input2, input3) -> {
acceptUnsafe(input1, input2, input3);
val value = supplier.applyUnsafe();
return value;
};
}
public default FuncUnit3 ignoreNullInput() {
return (input1, input2, input3) -> {
if ((input1 != null)
&& (input2 != null)
&& (input3 != null))
acceptUnsafe(input1, input2, input3);
};
}
public default FuncUnit1> wholly() {
return tuple -> {
val _1 = tuple._1();
val _2 = tuple._2();
val _3 = tuple._3();
acceptUnsafe(_1, _2, _3);
};
}
public default FuncUnit3 carelessly() {
return this::acceptCarelessly;
}
public default Func3> async() {
return this.thenReturnNull().async();
}
public default Func3, HasPromise, HasPromise, Promise