Class PPrism<S,​T,​A,​B>

  • Type Parameters:
    S - the source of a PPrism
    T - the modified source of a PPrism
    A - the target of a PPrism
    B - the modified target of a PPrism
    Direct Known Subclasses:
    Prism

    public abstract class PPrism<S,​T,​A,​B>
    extends java.lang.Object
    A PPrism can be seen as a pair of functions: - `getOrModify: S => T \/ A` - `reverseGet : B => T`

    A PPrism could also be defined as a weaker PIso where get can fail.

    Typically a PPrism or Prism encodes the relation between a Sum or CoProduct type (e.g. sealed trait) and one of it is element.

    PPrism stands for Polymorphic Prism as it set and modify methods change a type `A` to `B` and `S` to `T`. Prism is a PPrism where the type of target cannot be modified.

    A PPrism is also a valid Fold, POptional, PTraversal and PSetter

    • Constructor Detail

      • PPrism

        PPrism()
    • Method Detail

      • getOrModify

        public abstract Either<T,​A> getOrModify​(S s)
        get the target of a PPrism or modify the source in case there is no target
      • reverseGet

        public abstract T reverseGet​(B b)
        get the modified source of a PPrism
      • getOption

        public abstract Option<A> getOption​(S s)
        get the target of a PPrism or nothing if there is no target
      • modifyFunctionF

        public final <C> java.util.function.Function<S,​java.util.function.Function<C,​T>> modifyFunctionF​(java.util.function.Function<A,​java.util.function.Function<C,​B>> f)
        modify polymorphically the target of a PPrism with an Applicative function
      • modifyEitherF

        public final <L> java.util.function.Function<S,​Either<L,​T>> modifyEitherF​(java.util.function.Function<A,​Either<L,​B>> f)
        modify polymorphically the target of a PPrism with an Applicative function
      • modifyOptionF

        public final java.util.function.Function<S,​Option<T>> modifyOptionF​(java.util.function.Function<A,​Option<B>> f)
        modify polymorphically the target of a PPrism with an Applicative function
      • modifyPairF

        public final java.util.function.Function<S,​Pair<T,​T>> modifyPairF​(java.util.function.Function<A,​Pair<B,​B>> f)
        modify polymorphically the target of a PPrism with an Applicative function
      • modifySupplierF

        public final java.util.function.Function<S,​java.util.function.Supplier<T>> modifySupplierF​(java.util.function.Function<A,​java.util.function.Supplier<B>> f)
        modify polymorphically the target of a PPrism with an Applicative function
      • modifyIterableF

        public final java.util.function.Function<S,​java.lang.Iterable<T>> modifyIterableF​(java.util.function.Function<A,​java.lang.Iterable<B>> f)
        modify polymorphically the target of a PPrism with an Applicative function
      • modify

        public final java.util.function.Function<S,​T> modify​(java.util.function.Function<A,​B> f)
        modify polymorphically the target of a PPrism with a function
      • modifyOption

        public final java.util.function.Function<S,​Option<T>> modifyOption​(java.util.function.Function<A,​B> f)
        modify polymorphically the target of a PPrism with a function. return empty if the PPrism is not matching
      • set

        public final java.util.function.Function<S,​T> set​(B b)
        set polymorphically the target of a PPrism with a value
      • setOption

        public final java.util.function.Function<S,​Option<T>> setOption​(B b)
        set polymorphically the target of a PPrism with a value. return empty if the PPrism is not matching
      • isMatching

        public final boolean isMatching​(S s)
        check if a PPrism has a target
      • re

        public final Getter<B,​T> re()
        create a Getter from the modified target to the modified source of a PPrism
      • composeFold

        public final <C> Fold<S,​C> composeFold​(Fold<A,​C> other)
        compose a PPrism with a Fold
      • composePrism

        public final <C,​D> PPrism<S,​T,​C,​D> composePrism​(PPrism<A,​B,​C,​D> other)
        compose a PPrism with a PPrism
      • composeIso

        public final <C,​D> PPrism<S,​T,​C,​D> composeIso​(PIso<A,​B,​C,​D> other)
        compose a PPrism with a PIso
      • pId

        public static <S,​T> PPrism<S,​T,​S,​T> pId()
      • pPrism

        public static <S,​T,​A,​B> PPrism<S,​T,​A,​B> pPrism​(java.util.function.Function<S,​Either<T,​A>> getOrModify,
                                                                                           java.util.function.Function<B,​T> reverseGet)
        create a PPrism using the canonical functions: getOrModify and reverseGet