Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Lenses for getters and updates that can potentially fail with some error value. Like partial lenses, failing lenses are useful for creating accessor labels for multi constructor data types where projection and modification of fields will not always succeed. The error value can be used to report what caused the failure.
Synopsis
- type Lens e f o = Lens (Failing e) f o
- type Failing e = Kleisli (Either e)
- lens :: (f -> Either e o) -> ((o -> Either e i) -> f -> Either e g) -> Lens e (f -> g) (o -> i)
- get :: Lens e (f -> g) (o -> i) -> f -> Either e o
- modify :: Lens e (f -> g) (o -> i) -> (o -> i) -> f -> Either e g
- set :: Lens e (f -> g) (o -> i) -> i -> f -> Either e g
- embed :: Lens (->) (f -> g) (Either e o -> Either e i) -> Lens e (f -> g) (o -> i)
- set' :: Lens e (f -> f) (o -> o) -> o -> f -> f
- modify' :: Lens e (f -> f) (o -> o) -> (o -> o) -> f -> f
Documentation
type Lens e f o = Lens (Failing e) f o Source #
Lens type for situations in which the accessor functions can fail with some error information.
type Failing e = Kleisli (Either e) Source #
Context that represents computations that might fail with some error.
:: (f -> Either e o) | Getter. |
-> ((o -> Either e i) -> f -> Either e g) | Modifier. |
-> Lens e (f -> g) (o -> i) |
Create a lens that can fail from a getter and a modifier that can themselves potentially fail.
get :: Lens e (f -> g) (o -> i) -> f -> Either e 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 :: Lens e (f -> g) (o -> i) -> (o -> i) -> f -> Either e g Source #
Modifier for a lens that can fail. When the field to which the lens points
is not accessible this function returns Left
.
set :: Lens e (f -> g) (o -> i) -> i -> f -> Either e g Source #
Setter for a lens that can fail. When the field to which the lens points
is not accessible this function returns Left
.
embed :: Lens (->) (f -> g) (Either e o -> Either e i) -> Lens e (f -> g) (o -> i) Source #
Embed a total lens that points to an Either
field into a lens that might
fail.