| Portability | non-portable |
|---|---|
| Stability | experimental |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | Trustworthy |
Control.Lens.TH
Description
- makeLenses :: Name -> Q [Dec]
- makeLensesFor :: [(String, String)] -> Name -> Q [Dec]
- makeClassy :: Name -> Q [Dec]
- makeClassyFor :: String -> String -> [(String, String)] -> Name -> Q [Dec]
- makeIso :: Name -> Q [Dec]
- makePrisms :: Name -> Q [Dec]
- makeWrapped :: Name -> DecsQ
- makeFields :: Name -> Q [Dec]
- makeLensesWith :: LensRules -> Name -> Q [Dec]
- makeFieldsWith :: FieldRules -> Name -> Q [Dec]
- defaultRules :: LensRules
- defaultFieldRules :: FieldRules
- camelCaseFields :: FieldRules
- underscoreFields :: FieldRules
- data LensRules = LensRules (String -> Maybe String) (String -> Maybe String) (String -> Maybe (String, String)) (Set LensFlag)
- data FieldRules = FieldRules (String -> Maybe String) (String -> String) (String -> Maybe String) (String -> Maybe String)
- lensRules :: LensRules
- classyRules :: LensRules
- isoRules :: LensRules
- lensIso :: Lens' LensRules (String -> Maybe String)
- lensField :: Lens' LensRules (String -> Maybe String)
- lensClass :: Lens' LensRules (String -> Maybe (String, String))
- lensFlags :: Lens' LensRules (Set LensFlag)
- data LensFlag
- simpleLenses :: Lens' LensRules Bool
- partialLenses :: Lens' LensRules Bool
- buildTraversals :: Lens' LensRules Bool
- handleSingletons :: Lens' LensRules Bool
- singletonIso :: Lens' LensRules Bool
- singletonRequired :: Lens' LensRules Bool
- createClass :: Lens' LensRules Bool
- createInstance :: Lens' LensRules Bool
- classRequired :: Lens' LensRules Bool
- singletonAndField :: Lens' LensRules Bool
- generateSignatures :: Lens' LensRules Bool
Constructing Lenses Automatically
makeLenses :: Name -> Q [Dec]Source
Build lenses (and traversals) with a sensible default configuration.
makeLenses=makeLensesWithlensRules
makeLensesFor :: [(String, String)] -> Name -> Q [Dec]Source
Derive lenses and traversals, specifying explicit pairings
of (fieldName, lensName).
If you map multiple names to the same label, and it is present in the same
constructor then this will generate a Traversal.
e.g.
makeLensesFor[("_foo", "fooLens"), ("baz", "lbaz")] ''FoomakeLensesFor[("_barX", "bar"), ("_barY", "bar")] ''Bar
makeClassy :: Name -> Q [Dec]Source
Make lenses and traversals for a type, and create a class when the type has no arguments.
e.g.
data Foo = Foo { _fooX, _fooY :: Int }
makeClassy ''Foo
will create
class HasFoo t where foo ::SimpleLenst Foo instance HasFoo Foo where foo =idfooX, fooY :: HasFoo t =>SimpleLenstInt
makeClassy=makeLensesWithclassyRules
makeClassyFor :: String -> String -> [(String, String)] -> Name -> Q [Dec]Source
Derive lenses and traversals, using a named wrapper class, and
specifying explicit pairings of (fieldName, traversalName).
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.
e.g.
newtypeLista =List[a]makeIso''List
will create
list::Iso[a] [b] (Lista) (Listb)
makeIso=makeLensesWithisoRules
makeWrapped :: Name -> DecsQSource
Build Wrapped instance for a given newtype
makeFields :: Name -> Q [Dec]Source
makeFields =makeFieldsWithdefaultFieldRules
Configuring Lenses
makeFieldsWith :: FieldRules -> Name -> Q [Dec]Source
Make fields with the specified FieldRules.
defaultRules :: LensRulesSource
Default LensRules.
defaultFieldRules :: FieldRulesSource
defaultFieldRules = camelCaseFieldscamelCaseFields :: FieldRulesSource
Field rules for fields in the form prefixFieldname
underscoreFields :: FieldRulesSource
Field rules for fields in the form _prefix_fieldname
This configuration describes the options we'll be using to make isomorphisms or lenses.
data FieldRules Source
Rules for making fairly simple partial lenses, ignoring the special cases for isomorphisms and traversals, and not making any classes.
classyRules :: LensRulesSource
Rules for making lenses and traversals that precompose another Lens.
lensClass :: 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 :: 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.
Flags for Lens construction
buildTraversals :: Lens' LensRules BoolSource
In the situations that a Lens would be partial, when partialLenses is
used, this flag instead causes traversals to be generated. Only one can be
used, and if neither are, then compile-time errors are generated.
handleSingletons :: Lens' LensRules BoolSource
Handle singleton constructors specially.
singletonRequired :: Lens' LensRules BoolSource
Expect a single constructor, single field newtype or data type.
generateSignatures :: Lens' LensRules BoolSource
Indicate whether or not to supply the signatures for the generated lenses.
Disabling this can be useful if you want to provide a more restricted type signature or if you want to supply hand-written haddocks.