Skip to content

Instantly share code, notes, and snippets.

@russmatney
Created May 12, 2018 03:34
Show Gist options
  • Save russmatney/8d79256662fa34eacd75d15382d6b2a9 to your computer and use it in GitHub Desktop.
Save russmatney/8d79256662fa34eacd75d15382d6b2a9 to your computer and use it in GitHub Desktop.
composedViewExamples :: IO ()
composedViewExamples = do
let
bob = User (UserName "bob") 42 Nothing HM.empty
fitzgerald = Pet (PetName "Fitzgerald")
jeff = User (UserName "jeff") 42 (Just fitzgerald) HM.empty
print "Bob's pet's name is: "
print $ preview (pet . _Just . petName) bob
-- Nothing
print $ bob ^? pet . _Just . petName
-- Nothing
print "Jeff's pet's name is: "
print $ preview (pet . _Just . petName) jeff
-- Just (PetName "Fitzgerald")
print $ jeff ^? pet . _Just . petName
-- Just (PetName "Fitzgerald")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment