Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// ============================================================================
// 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 java.util.function.BiConsumer;
import functionalj.functions.ThrowFuncs;
import functionalj.promise.HasPromise;
import functionalj.promise.Promise;
import functionalj.tuple.Tuple2;
import lombok.val;
@FunctionalInterface
public interface FuncUnit2 extends BiConsumer {
public static FuncUnit2 of(FuncUnit2 consumer) {
return consumer;
}
public static FuncUnit2 funcUnit2(FuncUnit2 consumer) {
return consumer;
}
public static FuncUnit2 from(BiConsumer consumer) {
return consumer::accept;
}
public void acceptUnsafe(INPUT1 input1, INPUT2 input2) throws Exception;
public default void accept(INPUT1 input1, INPUT2 input2) {
try {
acceptUnsafe(input1, input2);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw ThrowFuncs.exceptionTransformer.value().apply(e);
}
}
public default void acceptCarelessly(INPUT1 input1, INPUT2 input2) {
try {
acceptUnsafe(input1, input2);
} catch (Exception e) {
}
}
public default FuncUnit2 then(FuncUnit0 after) {
requireNonNull(after);
return (input1, input2) -> {
acceptUnsafe(input1, input2);
after.runUnsafe();
};
}
public default FuncUnit2 then(FuncUnit2 super INPUT1, ? super INPUT2> after) {
requireNonNull(after);
return (input1, input2) -> {
acceptUnsafe(input1, input2);
after.acceptUnsafe(input1, input2);
};
}
public default Func2 thenReturnNull() {
return thenReturn(null);
}
public default Func2 thenReturn(T value) {
return (input1, input2) -> {
acceptUnsafe(input1, input2);
return value;
};
}
public default Func2 thenGet(Func0 supplier) {
requireNonNull(supplier);
return (input1, input2) -> {
acceptUnsafe(input1, input2);
val value = supplier.applyUnsafe();
return value;
};
}
public default FuncUnit2 ignoreNullInput() {
return (input1, input2) -> {
if ((input1 != null)
&& (input2 != null))
acceptUnsafe(input1, input2);
};
}
public default FuncUnit1> wholly() {
return tuple -> {
val _1 = tuple._1();
val _2 = tuple._2();
acceptUnsafe(_1, _2);
};
}
public default FuncUnit2 carelessly() {
return this::acceptCarelessly;
}
public default Func2> async() {
return this.thenReturnNull().async();
}
public default Func2, HasPromise, Promise