1515import java .util .function .Function ;
1616
1717import static com .jnape .palatable .lambda .adt .Maybe .just ;
18+ import static com .jnape .palatable .lambda .functions .builtin .fn1 .Constantly .constantly ;
1819import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into .into ;
1920import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into1 .into1 ;
2021import 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,
103104 return new Partial <>(pred .contraMap (HCons ::head ), into1 (fn ));
104105 }
105106
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 ();
110117 }
111118
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+ }
112127
113128 public static <A , B , C , R > Partial <Tuple3 <A , B , C >, R > of (Predicate <? super A > aPredicate ,
114129 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
118133 into3 (fn ));
119134 }
120135
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+
121166 public static <A , B , C , D , R > Partial <Tuple4 <A , B , C , D >, R > of (Predicate <? super A > aPredicate ,
122167 Predicate <? super B > bPredicate ,
123168 Predicate <? super C > cPredicate ,
0 commit comments