15
15
import java .util .function .Function ;
16
16
17
17
import static com .jnape .palatable .lambda .adt .Maybe .just ;
18
+ import static com .jnape .palatable .lambda .functions .builtin .fn1 .Constantly .constantly ;
18
19
import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into .into ;
19
20
import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into1 .into1 ;
20
21
import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into3 .into3 ;
@@ -103,12 +104,26 @@ public static <A, R> Partial<SingletonHList<A>, R> of(Predicate<A> pred,
103
104
return new Partial <>(pred .contraMap (HCons ::head ), into1 (fn ));
104
105
}
105
106
106
- public static <A , B , R > Partial <Tuple2 <A , B >, R > of (Predicate <? super A > aPredicate ,
107
- Predicate <? super B > bPredicate ,
108
- BiFunction <? super A , ? super B , ? extends R > fn ) {
109
- return new Partial <>(t -> aPredicate .test (t ._1 ()) && bPredicate .test (t ._2 ()), into (fn ));
107
+ // public static <A, B, R> Partial<Tuple2<A, B>, R> of(Predicate<? super A> aPredicate,
108
+ // Predicate<? super B> bPredicate,
109
+ // BiFunction<? super A, ? super B, ? extends R> fn) {
110
+ // return new Partial<>(t -> aPredicate.test(t._1()) && bPredicate.test(t._2()), into(fn));
111
+ // }
112
+
113
+ public static <A , APrime , B , BPrime , R > Partial <Tuple2 <A , B >, R >of (Predicate <? super A > x ,
114
+ Predicate <? super B > y ,
115
+ BiFunction <? super A , ? super B , ? extends R > z ) {
116
+ throw new UnsupportedOperationException ();
110
117
}
111
118
119
+ public static <A , APrime , B , BPrime , R > Partial <Tuple2 <A , B >, R > of (
120
+ DestructuringPredicate <? super A , ? extends APrime > aPredicate ,
121
+ DestructuringPredicate <? super B , ? extends BPrime > bPredicate ,
122
+ BiFunction <? super APrime , ? super BPrime , ? extends R > fn ) {
123
+ return new Partial <>(t -> aPredicate .test (t ._1 ()) && bPredicate .test (t ._2 ()),
124
+ into ((a , b ) -> fn .apply (aPredicate .destructure (a ).orElse (null ),
125
+ bPredicate .destructure (b ).orElse (null ))));
126
+ }
112
127
113
128
public static <A , B , C , R > Partial <Tuple3 <A , B , C >, R > of (Predicate <? super A > aPredicate ,
114
129
Predicate <? super B > bPredicate ,
@@ -118,6 +133,36 @@ public static <A, B, C, R> Partial<Tuple3<A, B, C>, R> of(Predicate<? super A> a
118
133
into3 (fn ));
119
134
}
120
135
136
+ @ FunctionalInterface
137
+ public static interface DestructuringPredicate <A , B > extends Predicate <A > {
138
+ Maybe <B > destructure (A a );
139
+
140
+ @ Override
141
+ default Boolean apply (A a ) {
142
+ return destructure (a ).fmap (constantly (true )).orElse (false );
143
+ }
144
+ }
145
+
146
+ public static <A , APrime , B , C , R > Partial <Tuple3 <A , B , C >, R > of (
147
+ DestructuringPredicate <? super A , ? extends APrime > aPredicate ,
148
+ Predicate <? super B > bPredicate ,
149
+ Predicate <? super C > cPredicate ,
150
+ Fn3 <? super APrime , ? super B , ? super C , ? extends R > fn ) {
151
+ return new Partial <>(t -> aPredicate .test (t ._1 ()) && bPredicate .test (t ._2 ()) && cPredicate .test (t ._3 ()),
152
+ into3 ((ap , b , c ) -> fn .apply (aPredicate .destructure (ap ).orElseGet (null ), b , c )));
153
+ }
154
+
155
+ public static <A , APrime , B , BPrime , C , R > Partial <Tuple3 <A , B , C >, R > of (
156
+ DestructuringPredicate <? super A , ? extends APrime > aPredicate ,
157
+ DestructuringPredicate <? super B , ? extends BPrime > bPredicate ,
158
+ Predicate <? super C > cPredicate ,
159
+ Fn3 <? super APrime , ? super BPrime , ? super C , ? extends R > fn ) {
160
+ return new Partial <>(t -> aPredicate .test (t ._1 ()) && bPredicate .test (t ._2 ()) && cPredicate .test (t ._3 ()),
161
+ into3 ((a , b , c ) -> fn .apply (aPredicate .destructure (a ).orElseGet (null ),
162
+ bPredicate .destructure (b ).orElseGet (null ),
163
+ c )));
164
+ }
165
+
121
166
public static <A , B , C , D , R > Partial <Tuple4 <A , B , C , D >, R > of (Predicate <? super A > aPredicate ,
122
167
Predicate <? super B > bPredicate ,
123
168
Predicate <? super C > cPredicate ,
0 commit comments