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

Safe HaskellSafe-Inferred

Data.Label.Partial

Contents

Description

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

Documentation

type :~> f o = Lens Partial f oSource

Partial lens type for situations in which the accessor functions can fail.

type Partial = Kleisli MaybeSource

Context that represents computations that might silently fail.

lensSource

Arguments

:: (f -> Maybe o)

Getter.

-> ((o -> Maybe i) -> f -> Maybe g)

Modifier.

-> (f -> g) :~> (o -> i) 

Create a lens that can fail from a getter and a modifier that can themselves potentially fail.

get :: ((f -> g) :~> (o -> i)) -> f -> Maybe oSource

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 gSource

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 gSource

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

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

modify' :: ((f -> f) :~> (o -> o)) -> (o -> o) -> f -> fSource

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

Potentially removing modification.

update :: ((f -> b) :~> (o -> i)) -> (o -> Maybe i) -> f -> Maybe bSource

Like modify, but update allows, depending on the underlying lens, to remove items by modifying to Nothing.