Skip to content

Commit

Permalink
Merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
siy committed Dec 4, 2023
1 parent b05a698 commit 7f7b328
Show file tree
Hide file tree
Showing 103 changed files with 1,706 additions and 4,434 deletions.
23 changes: 23 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,27 @@

<artifactId>core</artifactId>
<name>Core Classes</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
153 changes: 67 additions & 86 deletions core/src/main/java/org/pragmatica/lang/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ public interface Functions {
* Function with no parameters (supplier). Provided for consistency.
*/
@FunctionalInterface
interface FN0<R> {
interface Fn0<R> {
R apply();
}

/**
* Function with one parameter.
*/
@FunctionalInterface
interface FN1<R, T1> {
interface Fn1<R, T1> {
R apply(T1 param1);

default <N> FN1<N, T1> then(FN1<N, R> function) {
default <N> Fn1<N, T1> then(Fn1<N, R> function) {
return v1 -> function.apply(apply(v1));
}

default <N> FN1<R, N> before(FN1<T1, N> function) {
default <N> Fn1<R, N> before(Fn1<T1, N> function) {
return v1 -> apply(function.apply(v1));
}

static <T> FN1<T, T> id() {
static <T> Fn1<T, T> id() {
return Functions::id;
}
}
Expand All @@ -52,128 +52,64 @@ static <T> FN1<T, T> id() {
* Function with two parameters.
*/
@FunctionalInterface
interface FN2<R, T1, T2> {
interface Fn2<R, T1, T2> {
R apply(T1 param1, T2 param2);

default FN1<R, T2> bind(T1 param) {
return v2 -> apply(param, v2);
}

default <N> FN2<N, T1, T2> then(FN1<N, R> function) {
return (v1, v2) -> function.apply(apply(v1, v2));
}
}

/**
* Function with three parameters.
*/
@FunctionalInterface
interface FN3<R, T1, T2, T3> {
interface Fn3<R, T1, T2, T3> {
R apply(T1 param1, T2 param2, T3 param3);

default FN2<R, T2, T3> bind(T1 param) {
return (v2, v3) -> apply(param, v2, v3);
}

default <N> FN3<N, T1, T2, T3> then(FN1<N, R> function) {
return (v1, v2, v3) -> function.apply(apply(v1, v2, v3));
}
}

/**
* Function with four parameters.
*/
@FunctionalInterface
interface FN4<R, T1, T2, T3, T4> {
interface Fn4<R, T1, T2, T3, T4> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4);

default FN3<R, T2, T3, T4> bind(T1 param) {
return (v2, v3, v4) -> apply(param, v2, v3, v4);
}

default <N> FN4<N, T1, T2, T3, T4> then(FN1<N, R> function) {
return (v1, v2, v3, v4) -> function.apply(apply(v1, v2, v3, v4));
}
}

/**
* Function with five parameters.
*/
@FunctionalInterface
interface FN5<R, T1, T2, T3, T4, T5> {
interface Fn5<R, T1, T2, T3, T4, T5> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5);

default FN4<R, T2, T3, T4, T5> bind(T1 param) {
return (v2, v3, v4, v5) -> apply(param, v2, v3, v4, v5);
}

default <N> FN5<N, T1, T2, T3, T4, T5> then(FN1<N, R> function) {
return (v1, v2, v3, v4, v5) -> function.apply(apply(v1, v2, v3, v4, v5));
}
}

/**
* Function with six parameters.
*/
@FunctionalInterface
interface FN6<R, T1, T2, T3, T4, T5, T6> {
interface Fn6<R, T1, T2, T3, T4, T5, T6> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6);

default FN5<R, T2, T3, T4, T5, T6> bind(T1 param) {
return (v2, v3, v4, v5, v6) -> apply(param, v2, v3, v4, v5, v6);
}

default <N> FN6<N, T1, T2, T3, T4, T5, T6> then(FN1<N, R> function) {
return (v1, v2, v3, v4, v5, v6) -> function.apply(apply(v1, v2, v3, v4, v5, v6));
}
}

/**
* Function with seven parameters.
*/
@FunctionalInterface
interface FN7<R, T1, T2, T3, T4, T5, T6, T7> {
interface Fn7<R, T1, T2, T3, T4, T5, T6, T7> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7);

default FN6<R, T2, T3, T4, T5, T6, T7> bind(T1 param) {
return (v2, v3, v4, v5, v6, v7) -> apply(param, v2, v3, v4, v5, v6, v7);
}

default <N> FN7<N, T1, T2, T3, T4, T5, T6, T7> then(FN1<N, R> function) {
return (v1, v2, v3, v4, v5, v6, v7) -> function.apply(apply(v1, v2, v3, v4, v5, v6, v7));
}
}

/**
* Function with eight parameters.
*/
@FunctionalInterface
interface FN8<R, T1, T2, T3, T4, T5, T6, T7, T8> {
interface Fn8<R, T1, T2, T3, T4, T5, T6, T7, T8> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8);

default FN7<R, T2, T3, T4, T5, T6, T7, T8> bind(T1 param) {
return (v2, v3, v4, v5, v6, v7, v8) -> apply(param, v2, v3, v4, v5, v6, v7, v8);
}

default <N> FN8<N, T1, T2, T3, T4, T5, T6, T7, T8> then(FN1<N, R> function) {
return (v1, v2, v3, v4, v5, v6, v7, v8) -> function.apply(apply(v1, v2, v3, v4, v5, v6, v7, v8));
}
}

/**
* Function with nine parameters.
*/
@FunctionalInterface
interface FN9<R, T1, T2, T3, T4, T5, T6, T7, T8, T9> {
interface Fn9<R, T1, T2, T3, T4, T5, T6, T7, T8, T9> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8, T9 param9);

default FN8<R, T2, T3, T4, T5, T6, T7, T8, T9> bind(T1 param) {
return (v2, v3, v4, v5, v6, v7, v8, v9) -> apply(param, v2, v3, v4, v5, v6, v7, v8, v9);
}

default <N> FN9<N, T1, T2, T3, T4, T5, T6, T7, T8, T9> then(FN1<N, R> function) {
return (v1, v2, v3, v4, v5, v6, v7, v8, v9) -> function.apply(apply(v1, v2, v3, v4, v5, v6, v7, v8, v9));
}
}

/**
Expand All @@ -187,23 +123,60 @@ static <T> T id(T value) {
* Supplier which can throw an exception.
*/
@FunctionalInterface
interface ThrowingSupplier<T> {
T get() throws Throwable;
interface ThrowingFn0<T> {
T apply() throws Throwable;
}

@FunctionalInterface
interface ThrowingFn1<R, T1> {
R apply(T1 v1) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn2<R, T1, T2> {
R apply(T1 v1, T2 v2) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn3<R, T1, T2, T3> {
R apply(T1 param1, T2 param2, T3 param3) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn4<R, T1, T2, T3, T4> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn5<R, T1, T2, T3, T4, T5> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn6<R, T1, T2, T3, T4, T5, T6> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn7<R, T1, T2, T3, T4, T5, T6, T7> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7) throws Throwable;
}

@FunctionalInterface
interface ThrowingFn8<R, T1, T2, T3, T4, T5, T6, T7, T8> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8) throws Throwable;
}

/**
* Consumer with three parameters.
*/
@FunctionalInterface
interface TriConsumer<T, K, V> {
void accept(T t, K k, V v);
interface ThrowingFn9<R, T1, T2, T3, T4, T5, T6, T7, T8, T9> {
R apply(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8, T9 param9) throws Throwable;
}

/**
* Function with variable argument list.
*/
@FunctionalInterface
interface FNx<R> {
interface FnX<R> {
R apply(Object... values);
}

Expand Down Expand Up @@ -238,7 +211,15 @@ static <T1, T2, T3, T4, T5, T6, T7> void unitFn(T1 param1, T2 param2, T3 param3,
static <T1, T2, T3, T4, T5, T6, T7, T8> void unitFn(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8) {
}

static <T1, T2, T3, T4, T5, T6, T7, T8, T9> void unitFn(T1 param1, T2 param2, T3 param3, T4 param4, T5 param5, T6 param6, T7 param7, T8 param8, T9 param9) {
static <T1, T2, T3, T4, T5, T6, T7, T8, T9> void unitFn(T1 param1,
T2 param2,
T3 param3,
T4 param4,
T5 param5,
T6 param6,
T7 param7,
T8 param8,
T9 param9) {
}

static <R, T1> R toNull(T1 value) {
Expand Down
Loading

0 comments on commit 7f7b328

Please sign in to comment.