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.
Synopsis
- 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 Source #
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 Source #
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 Source #
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 Source #
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) Source #
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 Source #
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 Source #
Like modify
but return behaves like the identity function when the field
could not be set.