Skip to content

Commit eeac935

Browse files
committed
feat: add functional
1 parent be73ba9 commit eeac935

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.lokic.javaplus.functional.predicate;
2+
3+
4+
import java.util.function.Predicate;
5+
6+
@FunctionalInterface
7+
public interface Predicate4<T1, T2, T3, T4> {
8+
boolean test(T1 t1, T2 t2, T3 t3, T4 t4);
9+
10+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $1(Predicate<T1> predicate) {
11+
return (t1, t2, t3, t4) -> predicate.test(t1);
12+
}
13+
14+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $2(Predicate<T2> predicate) {
15+
return (t1, t2, t3, t4) -> predicate.test(t2);
16+
}
17+
18+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $3(Predicate<T3> predicate) {
19+
return (t1, t2, t3, t4) -> predicate.test(t3);
20+
}
21+
22+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $4(Predicate<T4> predicate) {
23+
return (t1, t2, t3, t4) -> predicate.test(t4);
24+
}
25+
}

src/main/java/com/github/lokic/javaplus/functional/sneakythrows/SneakyThrowsFunctional.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ static <T> SneakyThrowsConsumer1<T> consumer(ThrowsConsumer1<T> throwsConsumer1)
88
return throwsConsumer1::throwableAccept;
99
}
1010

11+
static <T1, T2> SneakyThrowsConsumer2<T1, T2> consumer(ThrowsConsumer2<T1, T2> throwsConsumer) {
12+
return throwsConsumer::throwableAccept;
13+
}
14+
15+
static <T1, T2, T3> SneakyThrowsConsumer3<T1, T2, T3> consumer(ThrowsConsumer3<T1, T2, T3> throwsConsumer) {
16+
return throwsConsumer::throwableAccept;
17+
}
18+
19+
static <T1, T2, T3, T4> SneakyThrowsConsumer4<T1, T2, T3, T4> consumer(ThrowsConsumer4<T1, T2, T3, T4> throwsConsumer) {
20+
return throwsConsumer::throwableAccept;
21+
}
22+
1123
static <T, R> SneakyThrowsFunction1<T, R> function(ThrowsFunction1<T, R> throwsFunction1) {
1224
return throwsFunction1::throwableApply;
1325
}
@@ -20,6 +32,30 @@ static <T1, T2, T3, R> SneakyThrowsFunction3<T1, T2, T3, R> function(ThrowsFunct
2032
return throwsFunction3::throwableApply;
2133
}
2234

35+
static <T1, T2, T3, T4, R> SneakyThrowsFunction4<T1, T2, T3, T4, R> function(ThrowsFunction4<T1, T2, T3, T4, R> throwsFunction4) {
36+
return throwsFunction4::throwableApply;
37+
}
38+
39+
static <T1, T2, T3, T4, T5, R> SneakyThrowsFunction5<T1, T2, T3, T4, T5, R> function(ThrowsFunction5<T1, T2, T3, T4, T5, R> throwsFunction5) {
40+
return throwsFunction5::throwableApply;
41+
}
42+
43+
static <T1, T2, T3, T4, T5, T6, R> SneakyThrowsFunction6<T1, T2, T3, T4, T5, T6, R> function(ThrowsFunction6<T1, T2, T3, T4, T5, T6, R> throwsFunction6) {
44+
return throwsFunction6::throwableApply;
45+
}
46+
47+
static <T1, T2, T3, T4, T5, T6, T7, R> SneakyThrowsFunction7<T1, T2, T3, T4, T5, T6, T7, R> function(ThrowsFunction7<T1, T2, T3, T4, T5, T6, T7, R> throwsFunction7) {
48+
return throwsFunction7::throwableApply;
49+
}
50+
51+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> SneakyThrowsFunction8<T1, T2, T3, T4, T5, T6, T7, T8, R> function(ThrowsFunction8<T1, T2, T3, T4, T5, T6, T7, T8, R> throwsFunction8) {
52+
return throwsFunction8::throwableApply;
53+
}
54+
55+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> SneakyThrowsFunction9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> function(ThrowsFunction9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> throwsFunction9) {
56+
return throwsFunction9::throwableApply;
57+
}
58+
2359
static SneakyThrowsRunnable runnable(ThrowsRunnable throwsRunnable) {
2460
return throwsRunnable::throwableRun;
2561
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.lokic.javaplus.functional.tuple;
2+
3+
import com.github.lokic.javaplus.functional.consumer.Consumer4;
4+
import com.github.lokic.javaplus.tuple.Tuple4;
5+
6+
import java.util.function.Consumer;
7+
8+
@FunctionalInterface
9+
public interface TupleConsumer4<T1, T2, T3, T4> extends Consumer<Tuple4<T1, T2, T3, T4>>, Consumer4<T1, T2, T3, T4> {
10+
11+
@Override
12+
default void accept(Tuple4<T1, T2, T3, T4> tuple4) {
13+
accept(tuple4.getT1(), tuple4.getT2(), tuple4.getT3(), tuple4.getT4());
14+
}
15+
16+
}

src/main/java/com/github/lokic/javaplus/functional/tuple/TupleFunctional.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import com.github.lokic.javaplus.functional.consumer.Consumer2;
44
import com.github.lokic.javaplus.functional.consumer.Consumer3;
5+
import com.github.lokic.javaplus.functional.consumer.Consumer4;
56
import com.github.lokic.javaplus.functional.function.*;
67
import com.github.lokic.javaplus.functional.predicate.Predicate2;
78
import com.github.lokic.javaplus.functional.predicate.Predicate3;
9+
import com.github.lokic.javaplus.functional.predicate.Predicate4;
810

911
public interface TupleFunctional {
1012

@@ -16,6 +18,10 @@ static <T1, T2, T3> TupleConsumer3<T1, T2, T3> consumer(Consumer3<T1, T2, T3> co
1618
return consumer3::accept;
1719
}
1820

21+
static <T1, T2, T3, T4> TupleConsumer4<T1, T2, T3, T4> consumer(Consumer4<T1, T2, T3, T4> consumer4) {
22+
return consumer4::accept;
23+
}
24+
1925
static <T1, T2> TuplePredicate2<T1, T2> predicate(Predicate2<T1, T2> predicate2) {
2026
return predicate2::test;
2127
}
@@ -24,6 +30,10 @@ static <T1, T2, T3> TuplePredicate3<T1, T2, T3> predicate(Predicate3<T1, T2, T3>
2430
return predicate3::test;
2531
}
2632

33+
static <T1, T2, T3, T4> TuplePredicate4<T1, T2, T3, T4> predicate(Predicate4<T1, T2, T3, T4> predicate4) {
34+
return predicate4::test;
35+
}
36+
2737
static <T1, T2, R> TupleFunction2<T1, T2, R> function(Function2<T1, T2, R> function2) {
2838
return function2::apply;
2939
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.lokic.javaplus.functional.tuple;
2+
3+
import com.github.lokic.javaplus.functional.predicate.Predicate4;
4+
import com.github.lokic.javaplus.tuple.Tuple4;
5+
6+
import java.util.function.Predicate;
7+
8+
@FunctionalInterface
9+
public interface TuplePredicate4<T1, T2, T3, T4> extends Predicate<Tuple4<T1, T2, T3, T4>>, Predicate4<T1, T2, T3, T4> {
10+
11+
@Override
12+
default boolean test(Tuple4<T1, T2, T3, T4> tuple4) {
13+
return test(tuple4.getT1(), tuple4.getT2(), tuple4.getT3(), tuple4.getT4());
14+
}
15+
}

0 commit comments

Comments
 (0)