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

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

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

    A POptional could also be defined as a weaker PLens and weaker PPrism

    POptional stands for Polymorphic Optional as it set and modify methods change a type `A` to `B` and `S` to `T`. Optional is a POptional restricted to monomorphic updates: {{{ type Optional[S, A] = POptional[S, S, A, A] }}}

    • Constructor Detail

      • POptional

        POptional()
    • Method Detail

      • getOrModify

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

        public abstract java.util.function.Function<S,​T> set​(B b)
        get the modified source of a POptional
      • getOption

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

        public abstract <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 POptional with an Applicative function
      • modifyEitherF

        public abstract <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 POptional with an Applicative function
      • modifyOptionF

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

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

        public abstract 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 POptional with an Applicative function
      • modifyIterableF

        public abstract 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 POptional with an Applicative function
      • modify

        public abstract java.util.function.Function<S,​T> modify​(java.util.function.Function<A,​B> f)
        modify polymorphically the target of a POptional 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 POptional with a function. return empty if the POptional is not matching
      • setOption

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

        public final boolean isMatching​(S s)
        check if a POptional has a target
      • pId

        public static <S,​T> POptional<S,​T,​S,​T> pId()
      • pOptional

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