Skip to content

Instantly share code, notes, and snippets.

@russmatney
Created May 12, 2018 03:37
Show Gist options
  • Save russmatney/5f2a49fa124d6610182d8e36e3ddb4d6 to your computer and use it in GitHub Desktop.
Save russmatney/5f2a49fa124d6610182d8e36e3ddb4d6 to your computer and use it in GitHub Desktop.
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