Class MaybeLens


  • public final class MaybeLens
    extends java.lang.Object
    Lenses that operate on Maybe.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MaybeLens()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <V> Lens.Simple<V,​Maybe<V>> asMaybe()
      Convenience static factory method for creating a lens that focuses on a value as a Maybe.
      static <S,​T,​A,​B>
      Lens<S,​T,​Maybe<A>,​B>
      liftA​(Lens<S,​T,​A,​B> lens)
      Given a lens, lift A into Maybe.
      static <S,​T,​A,​B>
      Lens<S,​T,​A,​Maybe<B>>
      liftB​(Lens<S,​T,​A,​B> lens, B defaultB)
      Given a lens and a default B, lift B into Maybe.
      static <S,​T,​A,​B>
      Lens<Maybe<S>,​T,​A,​B>
      liftS​(Lens<S,​T,​A,​B> lens, S defaultS)
      Given a lens and a default S, lift S into Maybe.
      static <S,​T,​A,​B>
      Lens<S,​Maybe<T>,​A,​B>
      liftT​(Lens<S,​T,​A,​B> lens)
      Given a lens, lift T into Maybe.
      static <S,​T,​A,​B>
      Lens<S,​T,​A,​B>
      unLiftA​(Lens<S,​T,​Maybe<A>,​B> lens, A defaultA)
      Given a lens with A lifted into Maybe and a default A, flatten A back down.
      static <S,​T,​A,​B>
      Lens<S,​T,​A,​B>
      unLiftB​(Lens<S,​T,​A,​Maybe<B>> lens)
      Given a lens with B lifted into Maybe, flatten B back down.
      static <S,​T,​A,​B>
      Lens<S,​T,​A,​B>
      unLiftS​(Lens<Maybe<S>,​T,​A,​B> lens)
      Given a lens with S lifted into Maybe, flatten S back down.
      static <S,​T,​A,​B>
      Lens<S,​T,​A,​B>
      unLiftT​(Lens<S,​Maybe<T>,​A,​B> lens, T defaultT)
      Given a lens with T lifted into Maybe and a default T, flatten T back down.
      • Methods inherited from class java.lang.Object

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

      • MaybeLens

        private MaybeLens()
    • Method Detail

      • liftS

        public static <S,​T,​A,​B> Lens<Maybe<S>,​T,​A,​B> liftS​(Lens<S,​T,​A,​B> lens,
                                                                                               S defaultS)
        Given a lens and a default S, lift S into Maybe.

        Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value B where S is Maybe.nothing().

        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        defaultS - the S to use if Maybe.nothing() is given
        Returns:
        the lens with S lifted
      • liftT

        public static <S,​T,​A,​B> Lens<S,​Maybe<T>,​A,​B> liftT​(Lens<S,​T,​A,​B> lens)
        Given a lens, lift T into Maybe.
        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        Returns:
        the lens with T lifted
      • liftA

        public static <S,​T,​A,​B> Lens<S,​T,​Maybe<A>,​B> liftA​(Lens<S,​T,​A,​B> lens)
        Given a lens, lift A into Maybe.
        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        Returns:
        the lens with A lifted
      • liftB

        public static <S,​T,​A,​B> Lens<S,​T,​A,​Maybe<B>> liftB​(Lens<S,​T,​A,​B> lens,
                                                                                               B defaultB)
        Given a lens and a default B, lift B into Maybe.

        Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value B where S is Maybe.nothing().

        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        defaultB - the B to use if Maybe.nothing() is given
        Returns:
        the lens with B lifted
      • unLiftS

        public static <S,​T,​A,​B> Lens<S,​T,​A,​B> unLiftS​(Lens<Maybe<S>,​T,​A,​B> lens)
        Given a lens with S lifted into Maybe, flatten S back down.
        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        Returns:
        the lens with S flattened
      • unLiftT

        public static <S,​T,​A,​B> Lens<S,​T,​A,​B> unLiftT​(Lens<S,​Maybe<T>,​A,​B> lens,
                                                                                          T defaultT)
        Given a lens with T lifted into Maybe and a default T, flatten T back down.

        Note that while this lens is not *necessarily* unlawful, it probably is, since the only case where "you get back what you put in" would not be violated is if T could never be Maybe.nothing().

        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        defaultT - the T to use if lens produces Maybe.nothing()
        Returns:
        the lens with T flattened
      • unLiftA

        public static <S,​T,​A,​B> Lens<S,​T,​A,​B> unLiftA​(Lens<S,​T,​Maybe<A>,​B> lens,
                                                                                          A defaultA)
        Given a lens with A lifted into Maybe and a default A, flatten A back down.

        Note that while this lens is not *necessarily* unlawful, it probably is, since the only case where "putting back what you got changes nothing" would not be violated is if A could never be Maybe.nothing().

        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        defaultA - the A to use if lens produces Maybe.nothing()
        Returns:
        the lens with A flattened
      • unLiftB

        public static <S,​T,​A,​B> Lens<S,​T,​A,​B> unLiftB​(Lens<S,​T,​A,​Maybe<B>> lens)
        Given a lens with B lifted into Maybe, flatten B back down.
        Type Parameters:
        S - the type of the "larger" value for reading
        T - the type of the "larger" value for putting
        A - the type of the "smaller" value that is read
        B - the type of the "smaller" update value
        Parameters:
        lens - the lens
        Returns:
        the lens with B flattened
      • asMaybe

        public static <V> Lens.Simple<V,​Maybe<V>> asMaybe()
        Convenience static factory method for creating a lens that focuses on a value as a Maybe.
        Type Parameters:
        V - the value type
        Returns:
        a lens that focuses on the value as a Maybe