Skip to content

Commit b51e93f

Browse files
committed
adding unification parameter to Profunctor
1 parent b3306e4 commit b51e93f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/main/java/com/jnape/palatable/lambda/functions/Fn1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @param <B> The result type
1414
*/
1515
@FunctionalInterface
16-
public interface Fn1<A, B> extends Functor<B, Fn1<A, ?>>, Profunctor<A, B>, Function<A, B> {
16+
public interface Fn1<A, B> extends Functor<B, Fn1<A, ?>>, Profunctor<A, B, Fn1>, Function<A, B> {
1717

1818
/**
1919
* Invoke this function with the given argument.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @see Fn1
2020
*/
2121
@FunctionalInterface
22-
public interface Profunctor<A, B> {
22+
public interface Profunctor<A, B, PF extends Profunctor> {
2323

2424
/**
2525
* Contravariantly map over the left parameter.
@@ -28,7 +28,7 @@ public interface Profunctor<A, B> {
2828
* @param fn the mapping function
2929
* @return a profunctor over Z (the new left parameter type) and C (the same right parameter type)
3030
*/
31-
default <Z> Profunctor<Z, B> diMapL(Function<Z, A> fn) {
31+
default <Z> Profunctor<Z, B, PF> diMapL(Function<Z, A> fn) {
3232
return diMap(fn, id());
3333
}
3434

@@ -40,7 +40,7 @@ default <Z> Profunctor<Z, B> diMapL(Function<Z, A> fn) {
4040
* @param fn the mapping function
4141
* @return a profunctor over A (the same left parameter type) and C (the new right parameter type)
4242
*/
43-
default <C> Profunctor<A, C> diMapR(Function<B, C> fn) {
43+
default <C> Profunctor<A, C, PF> diMapR(Function<B, C> fn) {
4444
return diMap(id(), fn);
4545
}
4646

@@ -54,5 +54,5 @@ default <C> Profunctor<A, C> diMapR(Function<B, C> fn) {
5454
* @param rFn the right parameter mapping function
5555
* @return a profunctor over Z (the new left parameter type) and C (the new right parameter type)
5656
*/
57-
<Z, C> Profunctor<Z, C> diMap(Function<Z, A> lFn, Function<B, C> rFn);
57+
<Z, C> Profunctor<Z, C, PF> diMap(Function<Z, A> lFn, Function<B, C> rFn);
5858
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class ProfunctorTest {
1515
@Test
1616
public void diMapLUsesIdentityForRightDiMapFunction() {
1717
AtomicReference<Function> rightInvocation = new AtomicReference<>();
18-
Profunctor<String, Integer> profunctor = new InvocationRecordingProfunctor<>(new AtomicReference<>(), rightInvocation);
18+
Profunctor<String, Integer, InvocationRecordingProfunctor> profunctor = new InvocationRecordingProfunctor<>(new AtomicReference<>(), rightInvocation);
1919
profunctor.diMapL(Object::toString);
2020
assertThat(rightInvocation.get(), is(id()));
2121
}
2222

2323
@Test
2424
public void diMapRUsesIdentityForLeftDiMapFunction() {
2525
AtomicReference<Function> leftInvocation = new AtomicReference<>();
26-
Profunctor<String, Integer> profunctor = new InvocationRecordingProfunctor<>(leftInvocation, new AtomicReference<>());
26+
Profunctor<String, Integer, InvocationRecordingProfunctor> profunctor = new InvocationRecordingProfunctor<>(leftInvocation, new AtomicReference<>());
2727
profunctor.diMapR(String::valueOf);
2828
assertThat(leftInvocation.get(), is(id()));
2929
}

src/test/java/testsupport/applicatives/InvocationRecordingProfunctor.java

Lines changed: 3 additions & 3 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 InvocationRecordingProfunctor<A, B> implements Profunctor<A, B> {
8+
public final class InvocationRecordingProfunctor<A, B> implements Profunctor<A, B, InvocationRecordingProfunctor> {
99
private final AtomicReference<Function> leftFn;
1010
private final AtomicReference<Function> rightFn;
1111

@@ -17,9 +17,9 @@ public InvocationRecordingProfunctor(AtomicReference<Function> leftFn,
1717

1818
@Override
1919
@SuppressWarnings("unchecked")
20-
public <C, D> Profunctor<C, D> diMap(Function<C, A> lFn, Function<B, D> rFn) {
20+
public <C, D> InvocationRecordingProfunctor<C, D> diMap(Function<C, A> lFn, Function<B, D> rFn) {
2121
leftFn.set(lFn);
2222
rightFn.set(rFn);
23-
return (Profunctor<C, D>) this;
23+
return (InvocationRecordingProfunctor<C, D>) this;
2424
}
2525
}

0 commit comments

Comments
 (0)