fclabels-2.0.3: 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 Source

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

type Partial = Kleisli Maybe Source

Context that represents computations that might silently fail.

lens Source

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 Source

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 Source

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 Source

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 -> f Source

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 Source

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 Source

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