Last active
January 4, 2016 12:59
-
-
Save danidiaz/8624735 to your computer and use it in GitHub Desktop.
Experimenting with Control.Lens.At and "non"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ghci> at 1 ?~ "hello" $ M.empty | |
| fromList [(1,"hello")] | |
| ghci> at 1 .~ (Just "hello") $ M.empty | |
| fromList [(1,"hello")] | |
| ghci> at 1 .~ Nothing $ M.fromList [(1,"blah")] | |
| fromList [] | |
| ghci> (%~) (at 2) (maybe (Just "b") (\x -> Just $ x ++ "bbb")) (M.fromList [(2,"a")]) | |
| fromList [(2,"abbb")] | |
| ghci> Nothing ^. non 0 | |
| 0 | |
| ghci> M.empty & at "hello" . non M.empty . at "world" .~ Just "!!!" | |
| fromList [("hello",fromList [("world","!!!")])] | |
| -- Beware, this in a bad use of "non" | |
| ghci> M.fromList [("hello",0)] & at "hello" . non 0 %~ (const 0) | |
| fromList [] | |
| -- Beware, this in a bad use of "non" | |
| ghci> M.fromList [("hello",M.empty)] & at "hello" . non M.empty . at "world" .~ Just "!!!" | |
| fromList [("hello",fromList [("world","!!!")])] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment