Skip to content

Commit 74b0e58

Browse files
committed
Adding default #discardL and #discardR implementations for Applicatives
1 parent ade5e47 commit 74b0e58

16 files changed

Lines changed: 204 additions & 9 deletions

File tree

‎src/main/java/com/jnape/palatable/lambda/adt/Either.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ public <R2> Either<L, R2> zip(Applicative<Function<? super R, ? extends R2>, Eit
224224
return appFn.<Either<L, Function<? super R, ? extends R2>>>coerce().flatMap(this::biMapR);
225225
}
226226

227+
@Override
228+
public <R2> Either<L, R2> discardL(Applicative<R2, Either<L, ?>> appB) {
229+
return Applicative.super.discardL(appB).coerce();
230+
}
231+
232+
@Override
233+
public <R2> Either<L, R> discardR(Applicative<R2, Either<L, ?>> appB) {
234+
return Applicative.super.discardR(appB).coerce();
235+
}
236+
227237
/**
228238
* In the left case, returns an {@link Optional#empty}; otherwise, returns {@link Optional#ofNullable} around the
229239
* right value.

‎src/main/java/com/jnape/palatable/lambda/adt/choice/Choice2.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public <C> Choice2<A, C> zip(Applicative<Function<? super B, ? extends C>, Choic
6969
.match(Choice2::a, this::biMapR);
7070
}
7171

72+
@Override
73+
public <C> Choice2<A, C> discardL(Applicative<C, Choice2<A, ?>> appB) {
74+
return Applicative.super.discardL(appB).coerce();
75+
}
76+
77+
@Override
78+
public <C> Choice2<A, B> discardR(Applicative<C, Choice2<A, ?>> appB) {
79+
return Applicative.super.discardR(appB).coerce();
80+
}
81+
7282
/**
7383
* Static factory method for wrapping a value of type <code>A</code> in a {@link Choice2}.
7484
*

‎src/main/java/com/jnape/palatable/lambda/adt/choice/Choice3.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public <D> Choice3<A, B, D> zip(
6969
.match(Choice3::a, Choice3::b, this::biMapR);
7070
}
7171

72+
@Override
73+
public <D> Choice3<A, B, D> discardL(Applicative<D, Choice3<A, B, ?>> appB) {
74+
return Applicative.super.discardL(appB).coerce();
75+
}
76+
77+
@Override
78+
public <D> Choice3<A, B, C> discardR(Applicative<D, Choice3<A, B, ?>> appB) {
79+
return Applicative.super.discardR(appB).coerce();
80+
}
81+
7282
/**
7383
* Static factory method for wrapping a value of type <code>A</code> in a {@link Choice3}.
7484
*

‎src/main/java/com/jnape/palatable/lambda/adt/choice/Choice4.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public <E> Choice4<A, B, C, E> zip(Applicative<Function<? super D, ? extends E>,
7272
.match(Choice4::a, Choice4::b, Choice4::c, this::biMapR);
7373
}
7474

75+
@Override
76+
public <E> Choice4<A, B, C, E> discardL(Applicative<E, Choice4<A, B, C, ?>> appB) {
77+
return Applicative.super.discardL(appB).coerce();
78+
}
79+
80+
@Override
81+
public <E> Choice4<A, B, C, D> discardR(Applicative<E, Choice4<A, B, C, ?>> appB) {
82+
return Applicative.super.discardR(appB).coerce();
83+
}
84+
7585
/**
7686
* Static factory method for wrapping a value of type <code>A</code> in a {@link Choice4}.
7787
*

‎src/main/java/com/jnape/palatable/lambda/adt/choice/Choice5.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public <F> Choice5<A, B, C, D, F> biMapR(Function<? super E, ? extends F> fn) {
5252
}
5353

5454
@Override
55-
@SuppressWarnings("unchecked")
5655
public <F, G> Choice5<A, B, C, F, G> biMap(Function<? super D, ? extends F> lFn,
5756
Function<? super E, ? extends G> rFn) {
5857
return match(Choice5::a, Choice5::b, Choice5::c, d -> d(lFn.apply(d)), e -> e(rFn.apply(e)));
@@ -69,6 +68,16 @@ public <F> Choice5<A, B, C, D, F> zip(Applicative<Function<? super E, ? extends
6968
.match(Choice5::a, Choice5::b, Choice5::c, Choice5::d, this::biMapR);
7069
}
7170

71+
@Override
72+
public <F> Choice5<A, B, C, D, F> discardL(Applicative<F, Choice5<A, B, C, D, ?>> appB) {
73+
return Applicative.super.discardL(appB).coerce();
74+
}
75+
76+
@Override
77+
public <F> Choice5<A, B, C, D, E> discardR(Applicative<F, Choice5<A, B, C, D, ?>> appB) {
78+
return Applicative.super.discardR(appB).coerce();
79+
}
80+
7281
/**
7382
* Static factory method for wrapping a value of type <code>A</code> in a {@link Choice5}.
7483
*

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/SingletonHList.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,14 @@ public <_1Prime> SingletonHList<_1Prime> zip(
4545
.head()
4646
.apply(head()));
4747
}
48+
49+
@Override
50+
public <_1Prime> SingletonHList<_1Prime> discardL(Applicative<_1Prime, SingletonHList> appB) {
51+
return Applicative.super.discardL(appB).coerce();
52+
}
53+
54+
@Override
55+
public <_1Prime> SingletonHList<_1> discardR(Applicative<_1Prime, SingletonHList> appB) {
56+
return Applicative.super.discardR(appB).coerce();
57+
}
4858
}

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple2.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ public <_2Prime> Tuple2<_1, _2Prime> zip(
116116
return biMapR(appFn.<Tuple2<_1, Function<? super _2, ? extends _2Prime>>>coerce()._2());
117117
}
118118

119+
@Override
120+
public <_2Prime> Tuple2<_1, _2Prime> discardL(Applicative<_2Prime, Tuple2<_1, ?>> appB) {
121+
return Applicative.super.discardL(appB).coerce();
122+
}
123+
124+
@Override
125+
public <_2Prime> Tuple2<_1, _2> discardR(Applicative<_2Prime, Tuple2<_1, ?>> appB) {
126+
return Applicative.super.discardR(appB).coerce();
127+
}
128+
119129
/**
120130
* Static factory method for creating <code>Tuple2</code>s from {@link java.util.Map.Entry}s.
121131
*

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple3.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ public <_3Prime> Tuple3<_1, _2, _3Prime> zip(
112112
return biMapR(appFn.<Tuple3<_1, _2, Function<? super _3, ? extends _3Prime>>>coerce()._3());
113113
}
114114

115+
@Override
116+
public <_3Prime> Tuple3<_1, _2, _3Prime> discardL(Applicative<_3Prime, Tuple3<_1, _2, ?>> appB) {
117+
return Applicative.super.discardL(appB).coerce();
118+
}
119+
120+
@Override
121+
public <_3Prime> Tuple3<_1, _2, _3> discardR(Applicative<_3Prime, Tuple3<_1, _2, ?>> appB) {
122+
return Applicative.super.discardR(appB).coerce();
123+
}
124+
115125
/**
116126
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
117127
*

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple4.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ public <_4Prime> Tuple4<_1, _2, _3, _4Prime> zip(
124124
return biMapR(appFn.<Tuple4<_1, _2, _3, Function<? super _4, ? extends _4Prime>>>coerce()._4());
125125
}
126126

127+
@Override
128+
public <_4Prime> Tuple4<_1, _2, _3, _4Prime> discardL(Applicative<_4Prime, Tuple4<_1, _2, _3, ?>> appB) {
129+
return Applicative.super.discardL(appB).coerce();
130+
}
131+
132+
@Override
133+
public <_4Prime> Tuple4<_1, _2, _3, _4> discardR(Applicative<_4Prime, Tuple4<_1, _2, _3, ?>> appB) {
134+
return Applicative.super.discardR(appB).coerce();
135+
}
136+
127137
/**
128138
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
129139
*

‎src/main/java/com/jnape/palatable/lambda/adt/hlist/Tuple5.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ public <_5Prime> Tuple5<_1, _2, _3, _4, _5Prime> zip(
122122
return biMapR(appFn.<Tuple5<_1, _2, _3, _4, Function<? super _5, ? extends _5Prime>>>coerce()._5());
123123
}
124124

125+
@Override
126+
public <_5Prime> Tuple5<_1, _2, _3, _4, _5Prime> discardL(Applicative<_5Prime, Tuple5<_1, _2, _3, _4, ?>> appB) {
127+
return Applicative.super.discardL(appB).coerce();
128+
}
129+
130+
@Override
131+
public <_5Prime> Tuple5<_1, _2, _3, _4, _5> discardR(Applicative<_5Prime, Tuple5<_1, _2, _3, _4, ?>> appB) {
132+
return Applicative.super.discardR(appB).coerce();
133+
}
134+
125135
/**
126136
* Given a value of type <code>A</code>, produced an instance of this tuple with each slot set to that value.
127137
*

0 commit comments

Comments
 (0)