A variant of
updateProperty that uses the
FromJSON
instance for the update function. It mimics the aeson operator
.:. It creates a parser that modifies a setter with a parsed
function.
data HttpURL = HttpURL
{ _auth ∷ !Auth
, _domain ∷ !String
}
auth ∷ Functor f ⇒ (Auth → f Auth) → HttpURL → f HttpURL
auth f s = (\u → s { _auth = u }) <$> f (_auth s)
domain ∷ Functor f ⇒ (String → f String) → HttpURL → f HttpURL
domain f s = (\u → s { _domain = u }) <$> f (_domain s)
path ∷ Functor f ⇒ (String → f String) → HttpURL → f HttpURL
path f s = (\u → s { _path = u }) <$> f (_path s)
-- or with lenses and TemplateHaskell just:
-- $(makeLenses ''HttpURL)
instance FromJSON (HttpURL → HttpURL) where
parseJSON = withObject "HttpURL" $ \o → id
<$< auth %.: "auth" % o
<*< domain ..: "domain" % o