If I have lenses for a nested record, where each lens returns a Maybe
, how can I get them to compose, so that if anything in the "traversal" returns a Nothing
the final result is a Nothing
?
data Client = Client
{
clientProperties :: Maybe Properties
, ...
}
data Properties = Properties
{
propSmtpConfig :: Maybe SmtpConfig
, ...
}
c :: Client
c = undefined
smtp = c ^. (properties . smtpConfig) -- How to make these lenses compose?
Edit I tried a lot of options, but this is the best I could come up with. Looking for something cleaner:
(client ^. properties) >>= (view smtpConfig)