Created
May 12, 2018 03:37
-
-
Save russmatney/5f2a49fa124d6610182d8e36e3ddb4d6 to your computer and use it in GitHub Desktop.
This file contains 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
atIxNonExamples :: IO () | |
atIxNonExamples = do | |
let bob = User (UserName "bob") 42 Nothing HM.empty | |
-- if you were doing this for-real, you would impl and use Data.Default | |
defaultGoldItem = Item 0 0 | |
print "Return the value of Bob's gold, whether he has it or not." | |
print $ bob ^. inventory . at "gold" . non defaultGoldItem . value | |
-- 0 | |
print $ bob ^? inventory . at "gold" . _Just . value | |
-- Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment