fclabels-2.0.3.2: First class accessor labels implemented as lenses.

Safe Haskell | Safe
Language | Haskell98

Data.Label.Failing

Contents

- Seemingly total modifications.

Description

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 #

Lens type for situations in which the accessor functions can fail with some error information.

type Failing e = Kleisli (Either e) #

Context that represents computations that might fail with some error.

lens #

Arguments

:: (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 #

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 #

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 #

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) #

Embed a total lens that points to an `Either` field into a lens that might fail.

# Seemingly total modifications.

set' :: Lens e (f -> f) (o -> o) -> o -> f -> f #

Like `set` but return behaves like the identity function when the field could not be set.

modify' :: Lens e (f -> f) (o -> o) -> (o -> o) -> f -> f #

Like `modify` but return behaves like the identity function when the field could not be set.