Skip to content

Instantly share code, notes, and snippets.

@pierric
Last active October 21, 2020 11:44
Show Gist options
  • Save pierric/40ec4c99c05b71a30a8ac6907efc08bc to your computer and use it in GitHub Desktop.
Save pierric/40ec4c99c05b71a30a8ac6907efc08bc to your computer and use it in GitHub Desktop.
lens magic
m = HashMap.fromList [
("X", HashMap.fromList [("a", 0), ("b", 1)]),
("Y", HashMap.fromList [("a", 1)]),
("Z", HashMap.fromList [("b", 2)])
]
I want to extract all value with key "a" in the nested HashMap, and keep the root key.
> m ^.. (itraversed <. at "a" . folded) . withIndex
result is [("X", 0), ("Y", 1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment