Class MaybeLens
java.lang.Object
com.jnape.palatable.lambda.optics.lenses.MaybeLens
Lenses that operate on
Maybe
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> Lens.Simple
<V, Maybe<V>> asMaybe()
Convenience static factory method for creating a lens that focuses on a value as aMaybe
.Given a lens, liftA
intoMaybe
.Given a lens, liftT
intoMaybe
.static <S,
T, A, B>
Lens<S, T, A, B> static <S,
T, A, B>
Lens<S, T, A, B> static <S,
T, A, B>
Lens<S, T, A, B> static <S,
T, A, B>
Lens<S, T, A, B>
-
Constructor Details
-
MaybeLens
private MaybeLens()
-
-
Method Details
-
liftS
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
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
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
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
- 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
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
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
- 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
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
-