Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Monomorphic lenses where the getters and updates can potentially silently fail. Partial lenses are useful for creating accessor labels for multi constructor data types where projection and modification of fields will not always succeed.
- type (:~>) f o = Lens Partial f o
- type Partial = Kleisli Maybe
- lens :: (f -> Maybe o) -> ((o -> Maybe i) -> f -> Maybe g) -> (f -> g) :~> (o -> i)
- get :: ((f -> g) :~> (o -> i)) -> f -> Maybe o
- modify :: ((f -> g) :~> (o -> i)) -> (o -> i) -> f -> Maybe g
- set :: ((f -> g) :~> (o -> i)) -> i -> f -> Maybe g
- embed :: Lens (->) (f -> g) (Maybe o -> Maybe i) -> (f -> g) :~> (o -> i)
- set' :: ((f -> f) :~> (o -> o)) -> o -> f -> f
- modify' :: ((f -> f) :~> (o -> o)) -> (o -> o) -> f -> f
- update :: ((f -> b) :~> (o -> i)) -> (o -> Maybe i) -> f -> Maybe b
Documentation
type (:~>) f o = Lens Partial f o #
Partial lens type for situations in which the accessor functions can fail.
Create a lens that can fail from a getter and a modifier that can themselves potentially fail.
get :: ((f -> g) :~> (o -> i)) -> f -> Maybe o #
Getter for a lens that can fail. When the field to which the lens points
is not accessible the getter returns Nothing
.
modify :: ((f -> g) :~> (o -> i)) -> (o -> i) -> f -> Maybe g #
Modifier for a lens that can fail. When the field to which the lens points
is not accessible this function returns Nothing
.
set :: ((f -> g) :~> (o -> i)) -> i -> f -> Maybe g #
Setter for a lens that can fail. When the field to which the lens points
is not accessible this function returns Nothing
.
embed :: Lens (->) (f -> g) (Maybe o -> Maybe i) -> (f -> g) :~> (o -> i) #
Embed a total lens that points to a Maybe
field into a lens that might
fail.
Seemingly total modifications.
set' :: ((f -> f) :~> (o -> o)) -> o -> f -> f #
Like set
but return behaves like the identity function when the field
could not be set.
modify' :: ((f -> f) :~> (o -> o)) -> (o -> o) -> f -> f #
Like modify
but return behaves like the identity function when the field
could not be set.