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

Safe HaskellSafe
LanguageHaskell98

Data.Label.Failing

Contents

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

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.

lens Source #

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 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.

Seemingly total modifications.

set' :: Lens e (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' :: Lens e (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.