Package jsonvalues

Class Prism<S,​T>

  • Type Parameters:
    S - the source of a prism
    T - the target of a prism

    public class Prism<S,​T>
    extends Object
    A Prism is an optic that can be seen as a pair of functions: - getOptional: S -> Optional<T> - reverseGet : T -> S Typically a Prism encodes the relation between a Sum or CoProduct type and one of its element.
    • Field Detail

      • getOptional

        public final Function<S,​Optional<T>> getOptional
        get the target of a Prism or nothing if there is no target
      • reverseGet

        public final Function<T,​S> reverseGet
        get the modified source of a Prism
    • Method Detail

      • modify

        public final Function<S,​S> modify​(Function<T,​T> f)
        modify the target of a Prism with a function, returning the same source if the prism is not matching. Basically it means we dont care about the success of the operation
        Parameters:
        f - the function from T to T
        Returns:
        a function from S to S
      • modifyOptional

        public final Function<S,​Optional<S>> modifyOptional​(Function<T,​T> f)
        modify the target of a Prism with a function, returning empty if the prism is not matching. Unless modify, we need to know the success of the operation
        Parameters:
        f - the function from T to T
        Returns:
        a function from S to S
      • isEmpty

        public final boolean isEmpty​(S target)
        check if there is no target
        Parameters:
        target - the target
        Returns:
        true if there is no target
      • nonEmpty

        public final boolean nonEmpty​(S target)
        check if there is a target
        Parameters:
        target - the target
        Returns:
        true if there is a target
      • find

        public final Function<S,​Optional<T>> find​(Predicate<T> predicate)
        find if the target satisfies the predicate
        Parameters:
        predicate - the given predicate
        Returns:
        a function from the source to an optional target
      • exists

        public final Predicate<S> exists​(Predicate<T> predicate)
        check if there is a target and it satisfies the predicate
        Parameters:
        predicate - the given predicate
        Returns:
        a predicate on the source
      • all

        public final Predicate<S> all​(Predicate<T> predicate)
        check if there is no target or the target satisfies the predicate
        Parameters:
        predicate - the given predicate
        Returns:
        a predicate on the source