lens-1.9: Lenses, Folds and Traversals

PortabilityTemplateHaskell
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellTrustworthy

Control.Lens.TH

Contents

Description

 

Synopsis

Documentation

data LensRules Source

This configuration describes the options we'll be using to make isomorphisms or lenses

lensIso :: Simple Lens LensRules (String -> Maybe String)Source

Lens to access the convention for naming top level isomorphisms in our lens rules

Defaults to lowercasing the first letter of the constructor.

lensField :: Simple Lens LensRules (String -> Maybe String)Source

Lens to access the convention for naming fields in our lens rules

Defaults to stripping the _ off of the field name and lowercasing the name and rejecting the field if it doesn't start with an '_'.

lensClass :: Simple Lens LensRules (String -> Maybe (String, String))Source

Retrieve options such as the name of the class and method to put in it to build a class around monomorphic data types.

lensFlags :: Simple Lens LensRules (Set LensFlag)Source

Retrieve options such as the name of the class and method to put in it to build a class around monomorphic data types.

simpleLenses :: Simple Lens LensRules BoolSource

Only Generate valid Simple Lens lenses

handleSingletons :: Simple Lens LensRules BoolSource

Handle singleton constructors specially

singletonIso :: Simple Lens LensRules BoolSource

Use Iso for singleton constructors

singletonRequired :: Simple Lens LensRules BoolSource

Expect a single constructor, single field newtype or data type.

createClass :: Simple Lens LensRules BoolSource

Create the class if the constructor is simple and the lensClass rule matches

createInstance :: Simple Lens LensRules BoolSource

Create the instance if the constructor is simple and the lensClass rule matches

classRequired :: Simple Lens LensRules BoolSource

Die if the lensClass fails to match

Constructing Lenses Automatically

makeClassy :: Name -> Q [Dec]Source

Make 'classy lenses' for a type

 makeClassy = makeLensesWith classyRules

makeClassyFor :: String -> String -> [(String, String)] -> Name -> Q [Dec]Source

Derive lenses, specifying explicit pairings of (fieldName, lensName) using a wrapper class.

Example usage:

 makeClassyFor "HasFoo" "foo" [("_foo", "fooLens"), ("bar", "lbar")] ''Foo

makeIso :: Name -> Q [Dec]Source

Make a top level isomorphism injecting _into_ the type

The supplied name is required to be for a type with a single constructor that has a single argument

 makeIso = makeLensesWith isoRules

makeLenses :: Name -> Q [Dec]Source

Build lenses with a sensible default configuration

 makeLenses = makeLensesWith lensRules

makeLensesFor :: [(String, String)] -> Name -> Q [Dec]Source

Derive lenses, specifying explicit pairings of (fieldName, lensName).

Example usage:

 makeLensesFor [("_foo", "fooLens"), ("bar", "lbar")] ''Foo

makeLensesWith :: LensRules -> Name -> Q [Dec]Source

Build lenses with a custom configuration

lensRules :: LensRulesSource

Rules for making fairly simple lenses, ignoring the special cases for isomorphisms, and not making any classes.

classyRules :: LensRulesSource

Rules for making lenses that precompose another lens.

isoRules :: LensRulesSource

Rules for making an isomorphism from a data type

defaultRules :: LensRulesSource

Default lens rules