lens-family-th- Generate lens-family style lenses

Safe HaskellNone



Derive lenses for Lens.Family.

Example usage:

 {-# LANGUAGE TemplateHaskell #-}
 import Lens.Family
 import Lens.Family.TH
 data Foo a = Foo { _bar :: Int, _baz :: a }
            deriving (Show, Read, Eq, Ord)
 $(mkLenses ''Foo)



mkLenses :: Name -> Q [Dec]Source

Derive lenses for the record selectors in a single-constructor data declaration, or for the record selector in a newtype declaration. Lenses will only be generated for record fields which are prefixed with an underscore.

Example usage:

$(mkLenses ''Foo)

mkLensesBy :: (String -> Maybe String) -> Name -> Q [Dec]Source

Derive lenses with the provided name transformation and filtering function. Produce Just lensName to generate a lens of the resultant name, or Nothing to not generate a lens for the input record name.

Example usage:

 $(mkLensesBy (\n -> Just (n ++ "L")) ''Foo)

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

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

Example usage:

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