Package jsonvalues

Class Lens<S,​O>

  • Type Parameters:
    S - the source of a lens
    O - the target of a lens
    Direct Known Subclasses:
    JsArrayLens, JsBigIntLens, JsBoolLens, JsDecimalLens, JsDoubleLens, JsIntLens, JsLongLens, JsObjLens, JsPathPairLens, JsStrLens, JsValueLens, JsValuePairLens

    public class Lens<S,​O>
    extends 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 Detail

      • get

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

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

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

      • find

        public Function<S,​Optional<O>> find​(Predicate<O> predicate)
        find if the target satisfies the predicate
        Parameters:
        predicate - the predicate
        Returns:
        a function from the whole to an optional subpart
      • compose

        public <A> Function<S,​A> compose​(Lens<O,​A> other)
      • exists

        public Predicate<S> exists​(Predicate<O> predicate)
        check if there is a target and it satisfies the predicate
        Parameters:
        predicate - the predicate
        Returns:
        a predicate on the whole