Skip to content

Commit 5ca5a9f

Browse files
committed
Lens is a profunctor via mapS and mapT
1 parent b93cd07 commit 5ca5a9f

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jnape.palatable.lambda.functor;
22

33
import com.jnape.palatable.lambda.functions.Fn1;
4+
import com.jnape.palatable.lambda.lens.Lens;
45

56
import java.util.function.Function;
67

@@ -18,6 +19,7 @@
1819
* @see Functor
1920
* @see Bifunctor
2021
* @see Fn1
22+
* @see Lens
2123
*/
2224
@FunctionalInterface
2325
public interface Profunctor<A, B, PF extends Profunctor> {

‎src/main/java/com/jnape/palatable/lambda/lens/Lens.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.jnape.palatable.lambda.functions.Fn2;
44
import com.jnape.palatable.lambda.functor.Applicative;
55
import com.jnape.palatable.lambda.functor.Functor;
6+
import com.jnape.palatable.lambda.functor.Profunctor;
67

78
import java.util.function.BiFunction;
89
import java.util.function.Function;
@@ -133,7 +134,7 @@
133134
* @param <B> the type of the "smaller" update value
134135
*/
135136
@FunctionalInterface
136-
public interface Lens<S, T, A, B> extends Applicative<T, Lens<S, ?, A, B>> {
137+
public interface Lens<S, T, A, B> extends Applicative<T, Lens<S, ?, A, B>>, Profunctor<S, T, Lens<?, ?, A, B>> {
137138

138139
<F extends Functor, FT extends Functor<T, F>, FB extends Functor<B, F>> FT apply(
139140
Function<? super A, ? extends FB> fn, S s);
@@ -179,6 +180,11 @@ default <U> Lens<S, T, A, B> discardR(Applicative<U, Lens<S, ?, A, B>> appB) {
179180
return Applicative.super.discardR(appB).coerce();
180181
}
181182

183+
@Override
184+
default <R, U> Lens<R, U, A, B> diMap(Function<R, S> lFn, Function<T, U> rFn) {
185+
return mapS(lFn).mapT(rFn);
186+
}
187+
182188
/**
183189
* Contravariantly map <code>S</code> to <code>R</code>, yielding a new lens.
184190
*

0 commit comments

Comments
 (0)