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

Safe HaskellSafe
LanguageHaskell98

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

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

type Partial = Kleisli Maybe #

Context that represents computations that might silently fail.

lens #

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

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 #

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 #

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

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 #

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 #

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

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