Class MaybeLens
java.lang.Object
com.jnape.palatable.lambda.optics.lenses.MaybeLens
-
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, liftAintoMaybe.Given a lens, liftTintoMaybe.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, liftSintoMaybe.Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value
BwhereSisMaybe.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, liftTintoMaybe.- 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, liftAintoMaybe.- 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, liftBintoMaybe.Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value
BwhereSisMaybe.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 withTlifted intoMaybeand a defaultT, flattenTback 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
Tcould 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 withAlifted intoMaybeand a defaultA, flattenAback 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
Acould 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
-