Created
May 12, 2018 03:37
-
-
Save russmatney/3baef3888e458b20e466d0509b5f6dbc 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
toListOfExamples :: IO () | |
toListOfExamples = do | |
let tory = HM.fromList [ ("gold", Item 99 10) | |
, ("silver", Item 10 9) | |
] | |
bob = User (UserName "bob") 42 Nothing tory | |
print "A list of Bob's items" | |
print $ bob ^.. inventory . folded | |
-- [Item {_itemValue = 10, _itemWeight = 9},Item {_itemValue = 99, _itemWeight = 10}] | |
print $ toListOf (inventory . folded) bob | |
-- [Item {_itemValue = 10, _itemWeight = 9},Item {_itemValue = 99, _itemWeight = 10}] | |
print "Bob uses ifolded . asIndex to list itemNames." | |
print $ bob ^.. inventory . ifolded . asIndex | |
-- ["silver","gold"] | |
print "Bob's filtering to only his valuable items." | |
print $ | |
bob ^.. inventory . folded . filtered (\item -> (item ^. value) > 50) | |
-- [Item {_itemValue = 99, _itemWeight = 10}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment