3
3
import com .jnape .palatable .lambda .adt .coproduct .CoProduct2 ;
4
4
import com .jnape .palatable .lambda .adt .coproduct .CoProduct3 ;
5
5
import com .jnape .palatable .lambda .adt .hlist .Tuple2 ;
6
+ import com .jnape .palatable .lambda .functions .Fn1 ;
6
7
import com .jnape .palatable .lambda .functor .Applicative ;
7
8
import com .jnape .palatable .lambda .functor .Bifunctor ;
8
9
import com .jnape .palatable .lambda .functor .builtin .Lazy ;
9
10
import com .jnape .palatable .lambda .monad .Monad ;
10
11
import com .jnape .palatable .lambda .traversable .Traversable ;
11
12
12
13
import java .util .Objects ;
13
- import java .util .function .Function ;
14
14
15
15
import static com .jnape .palatable .lambda .adt .hlist .HList .tuple ;
16
16
import static com .jnape .palatable .lambda .functions .builtin .fn1 .Constantly .constantly ;
25
25
* @param <A> the first possible type
26
26
* @param <B> the second possible type
27
27
*/
28
- public abstract class These <A , B > implements CoProduct3 <A , B , Tuple2 <A , B >, These <A , B >>, Monad <B , These <A , ?>>, Bifunctor <A , B , These <?, ?>>, Traversable <B , These <A , ?>> {
28
+ public abstract class These <A , B > implements
29
+ CoProduct3 <A , B , Tuple2 <A , B >, These <A , B >>,
30
+ Monad <B , These <A , ?>>,
31
+ Bifunctor <A , B , These <?, ?>>,
32
+ Traversable <B , These <A , ?>> {
29
33
30
34
private These () {
31
35
}
@@ -34,16 +38,16 @@ private These() {
34
38
* {@inheritDoc}
35
39
*/
36
40
@ Override
37
- public final <C , D > These <C , D > biMap (Function <? super A , ? extends C > lFn ,
38
- Function <? super B , ? extends D > rFn ) {
41
+ public final <C , D > These <C , D > biMap (Fn1 <? super A , ? extends C > lFn ,
42
+ Fn1 <? super B , ? extends D > rFn ) {
39
43
return match (a -> a (lFn .apply (a )), b -> b (rFn .apply (b )), into ((a , b ) -> both (lFn .apply (a ), rFn .apply (b ))));
40
44
}
41
45
42
46
/**
43
47
* {@inheritDoc}
44
48
*/
45
49
@ Override
46
- public final <C > These <A , C > flatMap (Function <? super B , ? extends Monad <C , These <A , ?>>> f ) {
50
+ public final <C > These <A , C > flatMap (Fn1 <? super B , ? extends Monad <C , These <A , ?>>> f ) {
47
51
return match (These ::a , b -> f .apply (b ).coerce (), into ((a , b ) -> f .apply (b ).<These <A , C >>coerce ().biMapL (constantly (a ))));
48
52
}
49
53
@@ -58,9 +62,8 @@ public final <C> These<A, C> pure(C c) {
58
62
@ Override
59
63
@ SuppressWarnings ("unchecked" )
60
64
public <C , App extends Applicative <?, App >, TravB extends Traversable <C , These <A , ?>>,
61
- AppB extends Applicative <C , App >,
62
- AppTrav extends Applicative <TravB , App >> AppTrav traverse (Function <? super B , ? extends AppB > fn ,
63
- Function <? super TravB , ? extends AppTrav > pure ) {
65
+ AppB extends Applicative <C , App >, AppTrav extends Applicative <TravB , App >>
66
+ AppTrav traverse (Fn1 <? super B , ? extends AppB > fn , Fn1 <? super TravB , ? extends AppTrav > pure ) {
64
67
return match (a -> pure .apply ((TravB ) a (a )),
65
68
b -> fn .apply (b ).fmap (this ::pure ).<TravB >fmap (Applicative ::coerce ).coerce (),
66
69
into ((a , b ) -> fn .apply (b ).fmap (c -> both (a , c )).<TravB >fmap (Applicative ::coerce ).coerce ()));
@@ -71,7 +74,7 @@ AppTrav extends Applicative<TravB, App>> AppTrav traverse(Function<? super B, ?
71
74
*/
72
75
@ Override
73
76
@ SuppressWarnings ("unchecked" )
74
- public final <Z > These <Z , B > biMapL (Function <? super A , ? extends Z > fn ) {
77
+ public final <Z > These <Z , B > biMapL (Fn1 <? super A , ? extends Z > fn ) {
75
78
return (These <Z , B >) Bifunctor .super .biMapL (fn );
76
79
}
77
80
@@ -80,29 +83,29 @@ public final <Z> These<Z, B> biMapL(Function<? super A, ? extends Z> fn) {
80
83
*/
81
84
@ Override
82
85
@ SuppressWarnings ("unchecked" )
83
- public final <C > These <A , C > biMapR (Function <? super B , ? extends C > fn ) {
86
+ public final <C > These <A , C > biMapR (Fn1 <? super B , ? extends C > fn ) {
84
87
return (These <A , C >) Bifunctor .super .biMapR (fn );
85
88
}
86
89
87
90
/**
88
91
* {@inheritDoc}
89
92
*/
90
93
@ Override
91
- public final <C > These <A , C > fmap (Function <? super B , ? extends C > fn ) {
94
+ public final <C > These <A , C > fmap (Fn1 <? super B , ? extends C > fn ) {
92
95
return Monad .super .<C >fmap (fn ).coerce ();
93
96
}
94
97
95
98
/**
96
99
* {@inheritDoc}
97
100
*/
98
101
@ Override
99
- public final <C > These <A , C > zip (Applicative <Function <? super B , ? extends C >, These <A , ?>> appFn ) {
102
+ public final <C > These <A , C > zip (Applicative <Fn1 <? super B , ? extends C >, These <A , ?>> appFn ) {
100
103
return Monad .super .zip (appFn ).coerce ();
101
104
}
102
105
103
106
@ Override
104
107
public <C > Lazy <These <A , C >> lazyZip (
105
- Lazy <? extends Applicative <Function <? super B , ? extends C >, These <A , ?>>> lazyAppFn ) {
108
+ Lazy <? extends Applicative <Fn1 <? super B , ? extends C >, These <A , ?>>> lazyAppFn ) {
106
109
return projectA ().<Lazy <These <A , C >>>fmap (a -> lazy (a (a )))
107
110
.orElseGet (() -> Monad .super .lazyZip (lazyAppFn ).fmap (Monad <C , These <A , ?>>::coerce ));
108
111
}
@@ -170,8 +173,8 @@ private _A(A a) {
170
173
}
171
174
172
175
@ Override
173
- public <R > R match (Function <? super A , ? extends R > aFn , Function <? super B , ? extends R > bFn ,
174
- Function <? super Tuple2 <A , B >, ? extends R > cFn ) {
176
+ public <R > R match (Fn1 <? super A , ? extends R > aFn , Fn1 <? super B , ? extends R > bFn ,
177
+ Fn1 <? super Tuple2 <A , B >, ? extends R > cFn ) {
175
178
return aFn .apply (a );
176
179
}
177
180
@@ -199,8 +202,8 @@ private _B(B b) {
199
202
}
200
203
201
204
@ Override
202
- public <R > R match (Function <? super A , ? extends R > aFn , Function <? super B , ? extends R > bFn ,
203
- Function <? super Tuple2 <A , B >, ? extends R > cFn ) {
205
+ public <R > R match (Fn1 <? super A , ? extends R > aFn , Fn1 <? super B , ? extends R > bFn ,
206
+ Fn1 <? super Tuple2 <A , B >, ? extends R > cFn ) {
204
207
return bFn .apply (b );
205
208
}
206
209
@@ -228,8 +231,8 @@ private Both(Tuple2<A, B> tuple) {
228
231
}
229
232
230
233
@ Override
231
- public <R > R match (Function <? super A , ? extends R > aFn , Function <? super B , ? extends R > bFn ,
232
- Function <? super Tuple2 <A , B >, ? extends R > cFn ) {
234
+ public <R > R match (Fn1 <? super A , ? extends R > aFn , Fn1 <? super B , ? extends R > bFn ,
235
+ Fn1 <? super Tuple2 <A , B >, ? extends R > cFn ) {
233
236
return cFn .apply (both );
234
237
}
235
238
0 commit comments