Last active
January 8, 2019 21:22
-
-
Save Porges/f0e0969d24227a473338ab39f0dcd5b3 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE TemplateHaskell #-} | |
module Main where | |
import Control.Lens.TH (makeLenses) | |
import Control.Lens (over, traverse, taking) | |
data Person = Person { _clothing :: [Clothing] } deriving Show | |
data Clothing | |
= Dress -- no pockets :( | |
| Jacket { _jacketLeftPocket :: [Item], _jacketRightPocket :: [Item] } | |
deriving Show | |
data Item | |
= Pen | |
| Chapstick | |
deriving Show | |
makeLenses ''Person | |
makeLenses ''Clothing | |
addChapstickToLeftPocket :: Person -> Person | |
addChapstickToLeftPocket = | |
over (clothing . taking 1 (traverse . jacketLeftPocket)) (Chapstick :) | |
main :: IO () | |
main = do | |
let p = Person [Dress, Jacket [] [], Jacket [] []] | |
print (addChapstickToLeftPocket p) | |
-- Person {_clothing = [Dress,Jacket {_jacketLeftPocket = [Chapstick], _jacketRightPocket = []},Jacket {_jacketLeftPocket = [], _jacketRightPocket = []}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment