Skip to content

Commit 68206c0

Browse files
committed
Adding Optic, a generic supertype for profunctor optics
1 parent 1d2749f commit 68206c0

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ might need to be reworked, and subtyping is obviously no longer supported.
4343
- `IO#unsafePerformAsyncIO` overloads for running `IO`s asynchronously
4444
- `IO`s automatically encode parallelism in composition
4545
- `IO#exceptionally` for recovering from failure during `IO` operation
46+
- `Optic`, a generic supertype for all profunctor optics
4647

4748
### Fixed
4849
- issue where certain ways to compose `Effect`s unintentionally nullified the effect
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.jnape.palatable.lambda.optics;
2+
3+
import com.jnape.palatable.lambda.functions.Fn1;
4+
import com.jnape.palatable.lambda.functor.Functor;
5+
import com.jnape.palatable.lambda.functor.Profunctor;
6+
7+
/**
8+
* A generic supertype representation for profunctor optics.
9+
* <p>
10+
* Precisely stated, for some {@link Profunctor} <code>P</code> and some {@link Functor} <code>F</code>, and for the
11+
* types <code>S</code> <code>T</code> <code>A</code> <code>B</code>, an
12+
* <code>{@link Optic}&lt;P, F, S, T, A, B&gt;</code> is a polymorphic function
13+
* <code>(P&lt;A, F&lt;B&gt;&gt; -&gt; P&lt;S, F&lt;T&gt;&gt;)</code> (existentially-quantified allowing for
14+
* covariance).
15+
*
16+
* @param <P> the {@link Profunctor} type
17+
* @param <F> the {@link Functor} type
18+
* @param <S> the left side of the output profunctor
19+
* @param <T> the right side's functor embedding of the output profunctor
20+
* @param <A> the left side of the input profunctor
21+
* @param <B> the right side's functor embedding of the input profunctor
22+
*/
23+
@FunctionalInterface
24+
public interface Optic<P extends Profunctor<?, ?, P>, F extends Functor<?, F>, S, T, A, B> {
25+
26+
<CoP extends P, CoF extends F,
27+
PAFB extends Profunctor<A, ? extends Functor<B, ? extends CoF>, ? extends CoP>,
28+
PSFT extends Profunctor<S, ? extends Functor<T, ? extends CoF>, ? extends CoP>> PSFT apply(PAFB pafb);
29+
30+
/**
31+
* Produce a monomorphic {@link Fn1} backed by this {@link Optic}.
32+
*
33+
* @param <CoP> the covariant bound on P
34+
* @param <CoF> the covariant bound on F
35+
* @param <PAFB> the fixed input profunctor type
36+
* @param <PSFT> the fixed output profunctor type
37+
* @return the monomorphic {@link Fn1} backed by this {@link Optic}
38+
*/
39+
default <CoP extends P, CoF extends F,
40+
PAFB extends Profunctor<A, ? extends Functor<B, ? extends CoF>, ? extends CoP>,
41+
PSFT extends Profunctor<S, ? extends Functor<T, ? extends CoF>, ? extends CoP>>
42+
Fn1<PAFB, PSFT> monomorphize() {
43+
return Optic.this::<CoP, CoF, PAFB, PSFT>apply;
44+
}
45+
}

0 commit comments

Comments
 (0)