module Brick.Types.TH
( suffixLenses
, suffixLensesWith
)
where
import qualified Language.Haskell.TH.Syntax as TH
import qualified Language.Haskell.TH.Lib as TH
import Lens.Micro ((&), (.~))
import Lens.Micro.TH (DefName(..), LensRules, makeLensesWith, lensRules, lensField)
suffixLenses :: TH.Name -> TH.DecsQ
suffixLenses :: Name -> DecsQ
suffixLenses = String -> LensRules -> Name -> DecsQ
suffixLensesWith String
"L" LensRules
lensRules
suffixLensesWith :: String -> LensRules -> TH.Name -> TH.DecsQ
suffixLensesWith :: String -> LensRules -> Name -> DecsQ
suffixLensesWith String
suffix LensRules
rs = LensRules -> Name -> DecsQ
makeLensesWith forall a b. (a -> b) -> a -> b
$
LensRules
rs forall a b. a -> (a -> b) -> b
& Lens' LensRules (Name -> [Name] -> Name -> [DefName])
lensField forall s t a b. ASetter s t a b -> b -> s -> t
.~ (\Name
_ [Name]
_ Name
name -> [Name -> DefName
TopName forall a b. (a -> b) -> a -> b
$ String -> Name
TH.mkName forall a b. (a -> b) -> a -> b
$ Name -> String
TH.nameBase Name
name forall a. [a] -> [a] -> [a]
++ String
suffix])