Last active
November 5, 2021 21:19
-
-
Save elect86/17b9e737644a306d9ba325719bd2baa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
public interface Arity0<O> extends | |
Consumer<O> | |
{ | |
void compute(@Container O out); | |
@Override | |
default void accept(final O out) | |
{ | |
compute(out); | |
} | |
} | |
@FunctionalInterface | |
public interface Arity3<I1, I2, I3> { | |
/** | |
* Performs this operation on the given arguments. | |
* | |
* @param in1 input argument 1. | |
* @param in2 input argument 2. | |
* @param in3 input argument 3. | |
*/ | |
void accept(final I1 in1, final I2 in2, final I3 in3); | |
/** | |
* Returns a composed {@code Consumer.Arity3} that performs, in sequence, | |
* this operation followed by the {@code after} operation. If performing | |
* either operation throws an exception, it is relayed to the caller of the | |
* composed operation. If performing this operation throws an exception, the | |
* {@code after} operation will not be performed. | |
* | |
* @param after the operation to perform after this operation | |
* @return a composed {@code Consumer.Arity3} that performs in sequence this | |
* operation followed by the {@code after} operation | |
* @throws NullPointerException if {@code after} is null | |
*/ | |
default Arity3<I1, I2, I3> andThen(Arity3<? super I1, ? super I2, ? super I3> after) | |
{ | |
Objects.requireNonNull(after); | |
return (in1, in2, in3) -> { | |
accept(in1, in2, in3); | |
after.accept(in1, in2, in3); | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface interface Arity0<O> : Consumer<O> { | |
fun compute(out: @Container O?) | |
override fun accept(out: O) { | |
compute(out) | |
} | |
} | |
fun interface Arity3<I1, I2, I3> { | |
/** | |
* Performs this operation on the given arguments. | |
* | |
* @param in1 input argument 1. | |
* @param in2 input argument 2. | |
* @param in3 input argument 3. | |
*/ | |
fun accept(in1: I1, in2: I2, in3: I3) | |
/** | |
* Returns a composed `Consumer.Arity3` that performs, in sequence, | |
* this operation followed by the `after` operation. If performing | |
* either operation throws an exception, it is relayed to the caller of the | |
* composed operation. If performing this operation throws an exception, the | |
* `after` operation will not be performed. | |
* | |
* @param after the operation to perform after this operation | |
* @return a composed `Consumer.Arity3` that performs in sequence this | |
* operation followed by the `after` operation | |
* @throws NullPointerException if `after` is null | |
*/ | |
fun andThen(after: Arity3<in I1, in I2, in I3>): Arity3<I1, I2, I3>? { | |
Objects.requireNonNull(after) | |
return Arity3 { in1: I1, in2: I2, in3: I3 -> | |
accept(in1, in2, in3) | |
after.accept(in1, in2, in3) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment