Skip to content

Commit 389bdbc

Browse files
committed
[jOOQ#391] Add Predicate<Tuple[N]<T...>> Tuple.predicate(Predicate[N]<T...>)
In order to beautify stream processing like that: Seq.of(tuple("marco", 24), tuple("luigi", 16), tuple("maria", 18)) .filter(Tuple.predicate((name, age) -> age > 17)) .map(Tuple.function((name, age) -> tuple("Sir / Madame " + name, age))) .forEach(Tuple.consumer((name, age) -> process(options, name, age)));
1 parent 7691de0 commit 389bdbc

File tree

2 files changed

+258
-76
lines changed
  • jOOL/src/main/java/org/jooq/lambda/tuple
  • jOOL-java-8/src/main/java/org/jooq/lambda/tuple

2 files changed

+258
-76
lines changed

jOOL-java-8/src/main/java/org/jooq/lambda/tuple/Tuple.java

Lines changed: 129 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,20 @@
1515
*/
1616
package org.jooq.lambda.tuple;
1717

18+
import org.jooq.lambda.Seq;
19+
import org.jooq.lambda.function.*;
20+
1821
import java.util.List;
1922
import java.util.Map;
20-
import java.util.stream.Collector;
2123
import java.util.function.BiConsumer;
2224
import java.util.function.BiFunction;
25+
import java.util.function.BiPredicate;
26+
import java.util.function.BooleanSupplier;
2327
import java.util.function.Consumer;
2428
import java.util.function.Function;
29+
import java.util.function.Predicate;
2530
import java.util.function.Supplier;
26-
27-
import org.jooq.lambda.Seq;
28-
import org.jooq.lambda.function.Consumer0;
29-
import org.jooq.lambda.function.Consumer1;
30-
import org.jooq.lambda.function.Consumer2;
31-
import org.jooq.lambda.function.Consumer3;
32-
import org.jooq.lambda.function.Consumer4;
33-
import org.jooq.lambda.function.Consumer5;
34-
import org.jooq.lambda.function.Consumer6;
35-
import org.jooq.lambda.function.Consumer7;
36-
import org.jooq.lambda.function.Consumer8;
37-
import org.jooq.lambda.function.Consumer9;
38-
import org.jooq.lambda.function.Consumer10;
39-
import org.jooq.lambda.function.Consumer11;
40-
import org.jooq.lambda.function.Consumer12;
41-
import org.jooq.lambda.function.Consumer13;
42-
import org.jooq.lambda.function.Consumer14;
43-
import org.jooq.lambda.function.Consumer15;
44-
import org.jooq.lambda.function.Consumer16;
45-
import org.jooq.lambda.function.Function0;
46-
import org.jooq.lambda.function.Function1;
47-
import org.jooq.lambda.function.Function2;
48-
import org.jooq.lambda.function.Function3;
49-
import org.jooq.lambda.function.Function4;
50-
import org.jooq.lambda.function.Function5;
51-
import org.jooq.lambda.function.Function6;
52-
import org.jooq.lambda.function.Function7;
53-
import org.jooq.lambda.function.Function8;
54-
import org.jooq.lambda.function.Function9;
55-
import org.jooq.lambda.function.Function10;
56-
import org.jooq.lambda.function.Function11;
57-
import org.jooq.lambda.function.Function12;
58-
import org.jooq.lambda.function.Function13;
59-
import org.jooq.lambda.function.Function14;
60-
import org.jooq.lambda.function.Function15;
61-
import org.jooq.lambda.function.Function16;
31+
import java.util.stream.Collector;
6232

6333
/**
6434
* A tuple.
@@ -424,6 +394,127 @@ static <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> C
424394
return t -> consumer.accept(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16);
425395
}
426396

397+
398+
/**
399+
* Construct a tuple predicate of degree 0.
400+
*/
401+
static <R> Predicate1<Tuple0> predicate(BooleanSupplier predicate) {
402+
return t -> predicate.getAsBoolean();
403+
}
404+
405+
/**
406+
* Construct a tuple predicate of degree 1.
407+
*/
408+
static <T1> Predicate1<Tuple1<T1>> predicate(Predicate<T1> predicate) {
409+
return t -> predicate.test(t.v1);
410+
}
411+
412+
/**
413+
* Construct a tuple predicate of degree 2.
414+
*/
415+
static <T1,T2> Predicate1<Tuple2<T1,T2>> predicate(BiPredicate<T1,T2> predicate) {
416+
return t -> predicate.test(t.v1, t.v2);
417+
}
418+
419+
/**
420+
* Construct a tuple predicate of degree 3.
421+
*/
422+
static <T1,T2,T3> Predicate1<Tuple3<T1,T2,T3>> predicate(Predicate3<T1,T2,T3> predicate) {
423+
return t -> predicate.test(t.v1, t.v2, t.v3);
424+
}
425+
426+
/**
427+
* Construct a tuple predicate of degree 4.
428+
*/
429+
static <T1,T2,T3,T4> Predicate1<Tuple4<T1,T2,T3,T4>> predicate(Predicate4<T1,T2,T3,T4> predicate) {
430+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4);
431+
}
432+
433+
/**
434+
* Construct a tuple predicate of degree 5.
435+
*/
436+
static <T1,T2,T3,T4,T5> Predicate1<Tuple5<T1,T2,T3,T4,T5>> predicate(Predicate5<T1,T2,T3,T4,T5> predicate) {
437+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5);
438+
}
439+
440+
/**
441+
* Construct a tuple predicate of degree 6.
442+
*/
443+
static <T1,T2,T3,T4,T5,T6> Predicate1<Tuple6<T1,T2,T3,T4,T5,T6>> predicate(Predicate6<T1,T2,T3,T4,T5,T6> predicate) {
444+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6);
445+
}
446+
447+
/**
448+
* Construct a tuple predicate of degree 7.
449+
*/
450+
static <T1,T2,T3,T4,T5,T6,T7> Predicate1<Tuple7<T1,T2,T3,T4,T5,T6,T7>> predicate(Predicate7<T1,T2,T3,T4,T5,T6,T7> predicate) {
451+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7);
452+
}
453+
454+
/**
455+
* Construct a tuple predicate of degree 8.
456+
*/
457+
static <T1,T2,T3,T4,T5,T6,T7,T8> Predicate1<Tuple8<T1,T2,T3,T4,T5,T6,T7,T8>> predicate(Predicate8<T1,T2,T3,T4,T5,T6,T7,T8> predicate) {
458+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8);
459+
}
460+
461+
/**
462+
* Construct a tuple predicate of degree 9.
463+
*/
464+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9> Predicate1<Tuple9<T1,T2,T3,T4,T5,T6,T7,T8,T9>> predicate(Predicate9<T1,T2,T3,T4,T5,T6,T7,T8,T9> predicate) {
465+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9);
466+
}
467+
468+
/**
469+
* Construct a tuple predicate of degree 10.
470+
*/
471+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> Predicate1<Tuple10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>> predicate(Predicate10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> predicate) {
472+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10);
473+
}
474+
475+
/**
476+
* Construct a tuple predicate of degree 11.
477+
*/
478+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> Predicate1<Tuple11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>> predicate(Predicate11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> predicate) {
479+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11);
480+
}
481+
482+
/**
483+
* Construct a tuple predicate of degree 12.
484+
*/
485+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> Predicate1<Tuple12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>> predicate(Predicate12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> predicate) {
486+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12);
487+
}
488+
489+
/**
490+
* Construct a tuple predicate of degree 13.
491+
*/
492+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> Predicate1<Tuple13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>> predicate(Predicate13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> predicate) {
493+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13);
494+
}
495+
496+
/**
497+
* Construct a tuple predicate of degree 14.
498+
*/
499+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> Predicate1<Tuple14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>> predicate(Predicate14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> predicate) {
500+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14);
501+
}
502+
503+
/**
504+
* Construct a tuple predicate of degree 15.
505+
*/
506+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> Predicate1<Tuple15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>> predicate(Predicate15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> predicate) {
507+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15);
508+
}
509+
510+
/**
511+
* Construct a tuple predicate of degree 16.
512+
*/
513+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> Predicate1<Tuple16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>> predicate(Predicate16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> predicate) {
514+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16);
515+
}
516+
517+
427518
/**
428519
* Construct a tuple collector of degree 1.
429520
*/
@@ -1428,4 +1519,4 @@ static <T extends Comparable<T>> Range<T> range(T lowerInclusive, T upperInclusi
14281519
* The degree of this tuple.
14291520
*/
14301521
int degree();
1431-
}
1522+
}

jOOL/src/main/java/org/jooq/lambda/tuple/Tuple.java

Lines changed: 129 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,20 @@
1515
*/
1616
package org.jooq.lambda.tuple;
1717

18+
import org.jooq.lambda.Seq;
19+
import org.jooq.lambda.function.*;
20+
1821
import java.util.List;
1922
import java.util.Map;
20-
import java.util.stream.Collector;
2123
import java.util.function.BiConsumer;
2224
import java.util.function.BiFunction;
25+
import java.util.function.BiPredicate;
26+
import java.util.function.BooleanSupplier;
2327
import java.util.function.Consumer;
2428
import java.util.function.Function;
29+
import java.util.function.Predicate;
2530
import java.util.function.Supplier;
26-
27-
import org.jooq.lambda.Seq;
28-
import org.jooq.lambda.function.Consumer0;
29-
import org.jooq.lambda.function.Consumer1;
30-
import org.jooq.lambda.function.Consumer2;
31-
import org.jooq.lambda.function.Consumer3;
32-
import org.jooq.lambda.function.Consumer4;
33-
import org.jooq.lambda.function.Consumer5;
34-
import org.jooq.lambda.function.Consumer6;
35-
import org.jooq.lambda.function.Consumer7;
36-
import org.jooq.lambda.function.Consumer8;
37-
import org.jooq.lambda.function.Consumer9;
38-
import org.jooq.lambda.function.Consumer10;
39-
import org.jooq.lambda.function.Consumer11;
40-
import org.jooq.lambda.function.Consumer12;
41-
import org.jooq.lambda.function.Consumer13;
42-
import org.jooq.lambda.function.Consumer14;
43-
import org.jooq.lambda.function.Consumer15;
44-
import org.jooq.lambda.function.Consumer16;
45-
import org.jooq.lambda.function.Function0;
46-
import org.jooq.lambda.function.Function1;
47-
import org.jooq.lambda.function.Function2;
48-
import org.jooq.lambda.function.Function3;
49-
import org.jooq.lambda.function.Function4;
50-
import org.jooq.lambda.function.Function5;
51-
import org.jooq.lambda.function.Function6;
52-
import org.jooq.lambda.function.Function7;
53-
import org.jooq.lambda.function.Function8;
54-
import org.jooq.lambda.function.Function9;
55-
import org.jooq.lambda.function.Function10;
56-
import org.jooq.lambda.function.Function11;
57-
import org.jooq.lambda.function.Function12;
58-
import org.jooq.lambda.function.Function13;
59-
import org.jooq.lambda.function.Function14;
60-
import org.jooq.lambda.function.Function15;
61-
import org.jooq.lambda.function.Function16;
31+
import java.util.stream.Collector;
6232

6333
/**
6434
* A tuple.
@@ -424,6 +394,127 @@ static <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> C
424394
return t -> consumer.accept(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16);
425395
}
426396

397+
398+
/**
399+
* Construct a tuple predicate of degree 0.
400+
*/
401+
static <R> Predicate1<Tuple0> predicate(BooleanSupplier predicate) {
402+
return t -> predicate.getAsBoolean();
403+
}
404+
405+
/**
406+
* Construct a tuple predicate of degree 1.
407+
*/
408+
static <T1> Predicate1<Tuple1<T1>> predicate(Predicate<T1> predicate) {
409+
return t -> predicate.test(t.v1);
410+
}
411+
412+
/**
413+
* Construct a tuple predicate of degree 2.
414+
*/
415+
static <T1,T2> Predicate1<Tuple2<T1,T2>> predicate(BiPredicate<T1,T2> predicate) {
416+
return t -> predicate.test(t.v1, t.v2);
417+
}
418+
419+
/**
420+
* Construct a tuple predicate of degree 3.
421+
*/
422+
static <T1,T2,T3> Predicate1<Tuple3<T1,T2,T3>> predicate(Predicate3<T1,T2,T3> predicate) {
423+
return t -> predicate.test(t.v1, t.v2, t.v3);
424+
}
425+
426+
/**
427+
* Construct a tuple predicate of degree 4.
428+
*/
429+
static <T1,T2,T3,T4> Predicate1<Tuple4<T1,T2,T3,T4>> predicate(Predicate4<T1,T2,T3,T4> predicate) {
430+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4);
431+
}
432+
433+
/**
434+
* Construct a tuple predicate of degree 5.
435+
*/
436+
static <T1,T2,T3,T4,T5> Predicate1<Tuple5<T1,T2,T3,T4,T5>> predicate(Predicate5<T1,T2,T3,T4,T5> predicate) {
437+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5);
438+
}
439+
440+
/**
441+
* Construct a tuple predicate of degree 6.
442+
*/
443+
static <T1,T2,T3,T4,T5,T6> Predicate1<Tuple6<T1,T2,T3,T4,T5,T6>> predicate(Predicate6<T1,T2,T3,T4,T5,T6> predicate) {
444+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6);
445+
}
446+
447+
/**
448+
* Construct a tuple predicate of degree 7.
449+
*/
450+
static <T1,T2,T3,T4,T5,T6,T7> Predicate1<Tuple7<T1,T2,T3,T4,T5,T6,T7>> predicate(Predicate7<T1,T2,T3,T4,T5,T6,T7> predicate) {
451+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7);
452+
}
453+
454+
/**
455+
* Construct a tuple predicate of degree 8.
456+
*/
457+
static <T1,T2,T3,T4,T5,T6,T7,T8> Predicate1<Tuple8<T1,T2,T3,T4,T5,T6,T7,T8>> predicate(Predicate8<T1,T2,T3,T4,T5,T6,T7,T8> predicate) {
458+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8);
459+
}
460+
461+
/**
462+
* Construct a tuple predicate of degree 9.
463+
*/
464+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9> Predicate1<Tuple9<T1,T2,T3,T4,T5,T6,T7,T8,T9>> predicate(Predicate9<T1,T2,T3,T4,T5,T6,T7,T8,T9> predicate) {
465+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9);
466+
}
467+
468+
/**
469+
* Construct a tuple predicate of degree 10.
470+
*/
471+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> Predicate1<Tuple10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>> predicate(Predicate10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> predicate) {
472+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10);
473+
}
474+
475+
/**
476+
* Construct a tuple predicate of degree 11.
477+
*/
478+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> Predicate1<Tuple11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>> predicate(Predicate11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> predicate) {
479+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11);
480+
}
481+
482+
/**
483+
* Construct a tuple predicate of degree 12.
484+
*/
485+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> Predicate1<Tuple12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>> predicate(Predicate12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> predicate) {
486+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12);
487+
}
488+
489+
/**
490+
* Construct a tuple predicate of degree 13.
491+
*/
492+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> Predicate1<Tuple13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>> predicate(Predicate13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> predicate) {
493+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13);
494+
}
495+
496+
/**
497+
* Construct a tuple predicate of degree 14.
498+
*/
499+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> Predicate1<Tuple14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>> predicate(Predicate14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> predicate) {
500+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14);
501+
}
502+
503+
/**
504+
* Construct a tuple predicate of degree 15.
505+
*/
506+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> Predicate1<Tuple15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>> predicate(Predicate15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> predicate) {
507+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15);
508+
}
509+
510+
/**
511+
* Construct a tuple predicate of degree 16.
512+
*/
513+
static <T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> Predicate1<Tuple16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>> predicate(Predicate16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> predicate) {
514+
return t -> predicate.test(t.v1, t.v2, t.v3, t.v4, t.v5, t.v6, t.v7, t.v8, t.v9, t.v10, t.v11, t.v12, t.v13, t.v14, t.v15, t.v16);
515+
}
516+
517+
427518
/**
428519
* Construct a tuple collector of degree 1.
429520
*/
@@ -1428,4 +1519,4 @@ static <T extends Comparable<T>> Range<T> range(T lowerInclusive, T upperInclusi
14281519
* The degree of this tuple.
14291520
*/
14301521
int degree();
1431-
}
1522+
}

0 commit comments

Comments
 (0)