Portability | TemplateHaskell |
---|---|
Stability | experimental |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | Trustworthy |
- data LensRules = LensRules (String -> Maybe String) (String -> Maybe String) (String -> Maybe (String, String)) (Set LensFlag)
- lensIso :: Simple Lens LensRules (String -> Maybe String)
- lensField :: Simple Lens LensRules (String -> Maybe String)
- lensClass :: Simple Lens LensRules (String -> Maybe (String, String))
- lensFlags :: Simple Lens LensRules (Set LensFlag)
- data LensFlag
- simpleLenses :: Simple Lens LensRules Bool
- handleSingletons :: Simple Lens LensRules Bool
- singletonIso :: Simple Lens LensRules Bool
- singletonRequired :: Simple Lens LensRules Bool
- createClass :: Simple Lens LensRules Bool
- createInstance :: Simple Lens LensRules Bool
- classRequired :: Simple Lens LensRules Bool
- makeClassy :: Name -> Q [Dec]
- makeClassyFor :: String -> String -> [(String, String)] -> Name -> Q [Dec]
- makeIso :: Name -> Q [Dec]
- makeLenses :: Name -> Q [Dec]
- makeLensesFor :: [(String, String)] -> Name -> Q [Dec]
- makeLensesWith :: LensRules -> Name -> Q [Dec]
- lensRules :: LensRules
- classyRules :: LensRules
- isoRules :: LensRules
- defaultRules :: LensRules
Documentation
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.
Flags for lens construction
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
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
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.
defaultRules :: LensRulesSource
Default lens rules