yall-0.2.1: Lenses with a southern twang

Safe HaskellNone





This is a subset of Lens, exporting only the basic API. Furthermore, get, lensM, getM, setM, and modifyM are exported with more restrictive types than are found in Data.Yall.Lens, for simplicity.

You should either import this module, or Lens.

Pure lenses

type :-> = LensM IdentitySource

a simple lens, suitable for single-constructor types

lens :: (a -> b) -> (a -> b -> a) -> a :-> bSource

Create a pure Lens from a getter and setter

 lens g = lensM (fmap return g) . fmap (fmap return)

get :: (a :-> b) -> a -> bSource

Run the getter function of a pure lens

set :: (a :-> b) -> a -> b -> aSource

Run the getter function of a pure lens

 set l b = runIdentity . setM l a

modify :: (a :-> b) -> (b -> b) -> a -> aSource

Partial lenses

type :~> = LensM MaybeSource

a lens that can fail in the Maybe monad on the outer type. Suitable for a normal lens on a multi-constructor type. The more general setM, getM, etc. can be used with this type.

lensM :: (a -> Maybe b) -> (a -> Maybe (b -> a)) -> a :~> bSource

Create a partial lens from a getter and setter

getM :: (a :~> b) -> a -> Maybe bSource

Try to run the getter function on a value

setM :: (a :~> b) -> a -> b -> Maybe aSource

try to run the setter function on an outer and new inner value

modifyM :: (a :~> b) -> (b -> b) -> a -> Maybe aSource

try to modify the inner type of a value