|
| 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}<P, F, S, T, A, B></code> is a polymorphic function |
| 13 | + * <code>(P<A, F<B>> -> P<S, F<T>>)</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