Package jsonvalues

Class Lens<S,​O>

  • Type Parameters:
    S - the source of a lens
    O - the target of a lens
    Direct Known Subclasses:
    JsBinaryLens, JsInstantLens

    public class Lens<S,​O>
    extends java.lang.Object
    A Lens is an optic that can be seen as a pair of functions: - get: S => O i.e. from an S, we can extract an O - set: (O, S) => S i.e. from an S and a O, we obtain a S. Unless a prism, to go back to S we need another S. Typically a Lens can be defined between a Product (e.g. record, tuple) and one of its component. Given a lens there are essentially three things you might want to do: -view the subpart -modify the whole by changing the subpart -combine this lens with another lens to look even deeper
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.function.Function<java.util.function.Predicate<O>,​java.util.function.Predicate<S>> exists
      check if there is a target and it satisfies the predicate
      java.util.function.Function<java.util.function.Predicate<O>,​java.util.function.Function<S,​java.util.Optional<O>>> find
      find if the target satisfies the predicate
      java.util.function.Function<S,​O> get
      function to view the part
      java.util.function.Function<java.util.function.Function<O,​O>,​java.util.function.Function<S,​S>> modify
      function to modify the whole by modifying the subpart with a function
      java.util.function.Function<O,​java.util.function.Function<S,​S>> set
      function to modify the whole by setting the subpart
    • Constructor Summary

      Constructors 
      Constructor Description
      Lens​(java.util.function.Function<S,​O> get, java.util.function.Function<O,​java.util.function.Function<S,​S>> set)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <B> Lens<S,​B> compose​(Lens<O,​B> other)
      Compose this lens with another one
      <T> Option<S,​T> compose​(Prism<O,​T> prism)
      Composing a Lens and a Prism returns and Optional
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • get

        public final java.util.function.Function<S,​O> get
        function to view the part
      • set

        public final java.util.function.Function<O,​java.util.function.Function<S,​S>> set
        function to modify the whole by setting the subpart
      • find

        public final java.util.function.Function<java.util.function.Predicate<O>,​java.util.function.Function<S,​java.util.Optional<O>>> find
        find if the target satisfies the predicate
      • exists

        public final java.util.function.Function<java.util.function.Predicate<O>,​java.util.function.Predicate<S>> exists
        check if there is a target and it satisfies the predicate
      • modify

        public final java.util.function.Function<java.util.function.Function<O,​O>,​java.util.function.Function<S,​S>> modify
        function to modify the whole by modifying the subpart with a function
    • Constructor Detail

      • Lens

        public Lens​(java.util.function.Function<S,​O> get,
                    java.util.function.Function<O,​java.util.function.Function<S,​S>> set)
    • Method Detail

      • compose

        public <T> Option<S,​T> compose​(Prism<O,​T> prism)
        Composing a Lens and a Prism returns and Optional
        Type Parameters:
        T - the type of the new focus of the Optional
        Parameters:
        prism - A Prism from the focus of the lens to the new focus of the Optional
        Returns:
        an Optional
      • compose

        public <B> Lens<S,​B> compose​(Lens<O,​B> other)
        Compose this lens with another one
        Type Parameters:
        B - the type of the focus on the new lens
        Parameters:
        other - the other lens
        Returns:
        a new Lens