[Haskell-cafe] Lenses and Nested Maps

Michael Sloan mgsloan at gmail.com
Tue Jun 18 03:55:11 UTC 2019


Hi Henry,

Yes, the "ix" function traverses into particular keys of map-like
structures https://www.stackage.org/haddock/lts-13.25/lens-4.17.1/Control-Lens-At.html#v:ix

So, (s & ix "bob" . ix 6 .~ 'c') will yield a modified Map with 'b'
changed to 'c'.

-Michael

On Mon, Jun 17, 2019 at 9:45 PM Henry Laxen <nadine.and.henry at pobox.com> wrote:
>
> Hi Cafe,
>
> Suppose I have:
>
> s :: Map String (Map Int Char)
> s =  M.fromList [("alice", M.fromList [(5,'a')]), ("bob", M.fromList [(6,'b')])]
>
> Is there any way to modify the 'b' entry easily using lenses?
>
> Thanks in advance.
> Best wishes,
> Henry Laxen
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list