KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using the lens package and and keep thinking there must be an easy solution to the following problem. Say I have some map (or any At instance) and a lens on its value type, ie aMap :: Map Int a aLens :: Simple Lens a b I want a getter g :: Getter (Map Int a) (Maybe b) This is because I often want to do something like this x :: Maybe b x = aMap^.at 3.g.aLens The intended semantics of course being that you get a Just value when you do so in the at lookup and Nothing otherwise. When one is setting instead of getting traverse works in place of g , ie newMap = at 3.traverse.aLens .~ whatever $ aMap but not when you are getting. Is there some ready built in lens the library that I have simply missed, or is there another simple way of achieving this in a single expression?
Tags (comma-separated)
Save Edits
Cancel