Skip to content

Commit 1d3b6e5

Browse files
committed
adding unification parameter to Bifunctor
1 parent d2c3238 commit 1d3b6e5

File tree

13 files changed

+20
-20
lines changed

13 files changed

+20
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @param <L> The left parameter type
2626
* @param <R> The right parameter type
2727
*/
28-
public abstract class Either<L, R> implements CoProduct2<L, R>, Functor<R, Either<L, ?>>, Bifunctor<L, R> {
28+
public abstract class Either<L, R> implements CoProduct2<L, R>, Functor<R, Either<L, ?>>, Bifunctor<L, R, Either> {
2929

3030
private Either() {
3131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @see Either
1919
* @see Choice3
2020
*/
21-
public abstract class Choice2<A, B> implements CoProduct2<A, B>, Functor<B, Choice2<A, ?>>, Bifunctor<A, B> {
21+
public abstract class Choice2<A, B> implements CoProduct2<A, B>, Functor<B, Choice2<A, ?>>, Bifunctor<A, B, Choice2> {
2222

2323
private Choice2() {
2424
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @see Choice2
1818
* @see Choice4
1919
*/
20-
public abstract class Choice3<A, B, C> implements CoProduct3<A, B, C>, Functor<C, Choice3<A, B, ?>>, Bifunctor<B, C> {
20+
public abstract class Choice3<A, B, C> implements CoProduct3<A, B, C>, Functor<C, Choice3<A, B, ?>>, Bifunctor<B, C, Choice3<A, ?, ?>> {
2121

2222
private Choice3() {
2323
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @see Choice3
1919
* @see Choice5
2020
*/
21-
public abstract class Choice4<A, B, C, D> implements CoProduct4<A, B, C, D>, Functor<D, Choice4<A, B, C, ?>>, Bifunctor<C, D> {
21+
public abstract class Choice4<A, B, C, D> implements CoProduct4<A, B, C, D>, Functor<D, Choice4<A, B, C, ?>>, Bifunctor<C, D, Choice4<A, B, ?, ?>> {
2222

2323
private Choice4() {
2424
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @param <E> a type parameter representing the fifth possible type of this choice
1919
* @see Choice4
2020
*/
21-
public abstract class Choice5<A, B, C, D, E> implements CoProduct5<A, B, C, D, E>, Functor<E, Choice5<A, B, C, D, ?>>, Bifunctor<D, E> {
21+
public abstract class Choice5<A, B, C, D, E> implements CoProduct5<A, B, C, D, E>, Functor<E, Choice5<A, B, C, D, ?>>, Bifunctor<D, E, Choice5<A, B, C, ?, ?>> {
2222

2323
private Choice5() {
2424
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @see Tuple4
2020
* @see Tuple5
2121
*/
22-
public class Tuple2<_1, _2> extends HCons<_1, SingletonHList<_2>> implements Map.Entry<_1, _2>, Functor<_2, Tuple2<_1, ?>>, Bifunctor<_1, _2> {
22+
public class Tuple2<_1, _2> extends HCons<_1, SingletonHList<_2>> implements Map.Entry<_1, _2>, Functor<_2, Tuple2<_1, ?>>, Bifunctor<_1, _2, Tuple2> {
2323

2424
private final _1 _1;
2525
private final _2 _2;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @see Tuple4
2020
* @see Tuple5
2121
*/
22-
public class Tuple3<_1, _2, _3> extends HCons<_1, Tuple2<_2, _3>> implements Functor<_3, Tuple3<_1, _2, ?>>, Bifunctor<_2, _3> {
22+
public class Tuple3<_1, _2, _3> extends HCons<_1, Tuple2<_2, _3>> implements Functor<_3, Tuple3<_1, _2, ?>>, Bifunctor<_2, _3, Tuple3<_1, ?, ?>> {
2323
private final _1 _1;
2424
private final _2 _2;
2525
private final _3 _3;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @see Tuple3
2121
* @see Tuple5
2222
*/
23-
public class Tuple4<_1, _2, _3, _4> extends HCons<_1, Tuple3<_2, _3, _4>> implements Functor<_4, Tuple4<_1, _2, _3, ?>>, Bifunctor<_3, _4> {
23+
public class Tuple4<_1, _2, _3, _4> extends HCons<_1, Tuple3<_2, _3, _4>> implements Functor<_4, Tuple4<_1, _2, _3, ?>>, Bifunctor<_3, _4, Tuple4<_1, _2, ?, ?>> {
2424
private final _1 _1;
2525
private final _2 _2;
2626
private final _3 _3;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @see Tuple3
2121
* @see Tuple4
2222
*/
23-
public class Tuple5<_1, _2, _3, _4, _5> extends HCons<_1, Tuple4<_2, _3, _4, _5>> implements Functor<_5, Tuple5<_1, _2, _3, _4, ?>>, Bifunctor<_4, _5> {
23+
public class Tuple5<_1, _2, _3, _4, _5> extends HCons<_1, Tuple4<_2, _3, _4, _5>> implements Functor<_5, Tuple5<_1, _2, _3, _4, ?>>, Bifunctor<_4, _5, Tuple5<_1, _2, _3, ?, ?>> {
2424
private final _1 _1;
2525
private final _2 _2;
2626
private final _3 _3;

src/main/java/com/jnape/palatable/lambda/functor/Bifunctor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @see com.jnape.palatable.lambda.adt.hlist.Tuple2
1717
*/
1818
@FunctionalInterface
19-
public interface Bifunctor<A, B> {
19+
public interface Bifunctor<A, B, BF extends Bifunctor> {
2020

2121
/**
2222
* Covariantly map over the left parameter.
@@ -25,7 +25,7 @@ public interface Bifunctor<A, B> {
2525
* @param fn the mapping function
2626
* @return a bifunctor over C (the new left parameter) and B (the same right parameter)
2727
*/
28-
default <C> Bifunctor<C, B> biMapL(Function<? super A, ? extends C> fn) {
28+
default <C> Bifunctor<C, B, BF> biMapL(Function<? super A, ? extends C> fn) {
2929
return biMap(fn, id());
3030
}
3131

@@ -37,7 +37,7 @@ default <C> Bifunctor<C, B> biMapL(Function<? super A, ? extends C> fn) {
3737
* @param fn the mapping function
3838
* @return a bifunctor over A (the same left parameter) and C (the new right parameter)
3939
*/
40-
default <C> Bifunctor<A, C> biMapR(Function<? super B, ? extends C> fn) {
40+
default <C> Bifunctor<A, C, BF> biMapR(Function<? super B, ? extends C> fn) {
4141
return biMap(id(), fn);
4242
}
4343

@@ -51,5 +51,5 @@ default <C> Bifunctor<A, C> biMapR(Function<? super B, ? extends C> fn) {
5151
* @param rFn the right parameter mapping function
5252
* @return a bifunctor over C (the new left parameter type) and D (the new right parameter type)
5353
*/
54-
<C, D> Bifunctor<C, D> biMap(Function<? super A, ? extends C> lFn, Function<? super B, ? extends D> rFn);
54+
<C, D> Bifunctor<C, D, BF> biMap(Function<? super A, ? extends C> lFn, Function<? super B, ? extends D> rFn);
5555
}

src/main/java/com/jnape/palatable/lambda/functor/builtin/Const.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @param <A> the left parameter type, and the type of the stored value
1515
* @param <B> the right (phantom) parameter type
1616
*/
17-
public final class Const<A, B> implements Functor<B, Const<A, ?>>, Bifunctor<A, B> {
17+
public final class Const<A, B> implements Functor<B, Const<A, ?>>, Bifunctor<A, B, Const> {
1818

1919
private final A a;
2020

src/test/java/com/jnape/palatable/lambda/functor/BifunctorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class BifunctorTest {
1515
@Test
1616
public void biMapLUsesIdentityForRightBiMapFunction() {
1717
AtomicReference<Function> rightInvocation = new AtomicReference<>();
18-
Bifunctor<String, Integer> bifunctor = new InvocationRecordingBifunctor<>(new AtomicReference<>(), rightInvocation);
18+
Bifunctor<String, Integer, InvocationRecordingBifunctor> bifunctor = new InvocationRecordingBifunctor<>(new AtomicReference<>(), rightInvocation);
1919
bifunctor.biMapL(String::toUpperCase);
2020
assertThat(rightInvocation.get(), is(id()));
2121
}
2222

2323
@Test
2424
public void biMapRUsesIdentityForLeftBiMapFunction() {
2525
AtomicReference<Function> leftInvocation = new AtomicReference<>();
26-
Bifunctor<String, Integer> bifunctor = new InvocationRecordingBifunctor<>(leftInvocation, new AtomicReference<>());
26+
Bifunctor<String, Integer, InvocationRecordingBifunctor> bifunctor = new InvocationRecordingBifunctor<>(leftInvocation, new AtomicReference<>());
2727
bifunctor.biMapR(String::valueOf);
2828
assertThat(leftInvocation.get(), is(id()));
2929
}

src/test/java/testsupport/applicatives/InvocationRecordingBifunctor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.concurrent.atomic.AtomicReference;
66
import java.util.function.Function;
77

8-
public final class InvocationRecordingBifunctor<A, B> implements Bifunctor<A, B> {
8+
public final class InvocationRecordingBifunctor<A, B> implements Bifunctor<A, B, InvocationRecordingBifunctor> {
99
private final AtomicReference<Function> leftFn;
1010
private final AtomicReference<Function> rightFn;
1111

@@ -17,10 +17,10 @@ public InvocationRecordingBifunctor(AtomicReference<Function> leftFn,
1717

1818
@Override
1919
@SuppressWarnings("unchecked")
20-
public <C, D> Bifunctor<C, D> biMap(Function<? super A, ? extends C> lFn,
21-
Function<? super B, ? extends D> rFn) {
20+
public <C, D> InvocationRecordingBifunctor<C, D> biMap(Function<? super A, ? extends C> lFn,
21+
Function<? super B, ? extends D> rFn) {
2222
leftFn.set(lFn);
2323
rightFn.set(rFn);
24-
return (Bifunctor<C, D>) this;
24+
return (InvocationRecordingBifunctor<C, D>) this;
2525
}
2626
}

0 commit comments

Comments
 (0)