A variant of the
setProperty that uses the default
parseJSON method from the
FromJSON instance to parse the
value of the property. Its usage pattern mimics the usage pattern of
the
.: operator from the aeson library.
data Auth = Auth
{ _user ∷ !String
, _pwd ∷ !String
}
user ∷ Functor f ⇒ (String → f String) → Auth → f Auth
user f s = (\u → s { _user = u }) <$> f (_user s)
pwd ∷ Functor f ⇒ (String → f String) → Auth → f Auth
pwd f s = (\p → s { _pwd = p }) <$> f (_pwd s)
-- or with lenses and TemplateHaskell just:
-- $(makeLenses ''Auth)
instance FromJSON (Auth → Auth) where
parseJSON = withObject "Auth" $ \o → id
<$< user ..: "user" % o
<*< pwd ..: "pwd" % o