Class MaybeLens
- java.lang.Object
-
- com.jnape.palatable.lambda.optics.lenses.MaybeLens
-
public final class MaybeLens extends java.lang.Object
Lenses that operate onMaybe
.
-
-
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 aMaybe
.static <S,T,A,B>
Lens<S,T,Maybe<A>,B>liftA(Lens<S,T,A,B> lens)
Given a lens, liftA
intoMaybe
.static <S,T,A,B>
Lens<S,T,A,Maybe<B>>liftB(Lens<S,T,A,B> lens, B defaultB)
static <S,T,A,B>
Lens<Maybe<S>,T,A,B>liftS(Lens<S,T,A,B> lens, S defaultS)
static <S,T,A,B>
Lens<S,Maybe<T>,A,B>liftT(Lens<S,T,A,B> lens)
Given a lens, liftT
intoMaybe
.static <S,T,A,B>
Lens<S,T,A,B>unLiftA(Lens<S,T,Maybe<A>,B> lens, A defaultA)
static <S,T,A,B>
Lens<S,T,A,B>unLiftB(Lens<S,T,A,Maybe<B>> lens)
static <S,T,A,B>
Lens<S,T,A,B>unLiftS(Lens<Maybe<S>,T,A,B> lens)
static <S,T,A,B>
Lens<S,T,A,B>unLiftT(Lens<S,Maybe<T>,A,B> lens, T defaultT)
-
-
-
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 defaultS
, liftS
intoMaybe
.Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value
B
whereS
isMaybe.nothing()
.- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- the type of the "smaller" update value- Parameters:
lens
- the lensdefaultS
- the S to use ifMaybe.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, liftT
intoMaybe
.- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- 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, liftA
intoMaybe
.- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- 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 defaultB
, liftB
intoMaybe
.Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value
B
whereS
isMaybe.nothing()
.- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- the type of the "smaller" update value- Parameters:
lens
- the lensdefaultB
- the B to use ifMaybe.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)
- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- 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 withT
lifted intoMaybe
and a defaultT
, flattenT
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 beMaybe.nothing()
.- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- the type of the "smaller" update value- Parameters:
lens
- the lensdefaultT
- the T to use if lens producesMaybe.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 withA
lifted intoMaybe
and a defaultA
, flattenA
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 beMaybe.nothing()
.- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- the type of the "smaller" update value- Parameters:
lens
- the lensdefaultA
- the A to use if lens producesMaybe.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)
- Type Parameters:
S
- the type of the "larger" value for readingT
- the type of the "larger" value for puttingA
- the type of the "smaller" value that is readB
- 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 aMaybe
.- Type Parameters:
V
- the value type- Returns:
- a lens that focuses on the value as a
Maybe
-
-