Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE RankNTypes #-}
- data Person = Person { _name :: String , _age :: Int } deriving Show
- makeLenses 'Person
- example :: Person
- example = Person "Bob" 55
- pry :: Lens' r x -> Iso' r (x -> r,x)
- pry l = iso (\r -> (\x -> set l x r, view l r)) (uncurry ($))
- consName :: Prism' Person (Char,Person)
- consName =
- pry name . aside _Cons . iso (\(a,(b,c)) -> (b,(a,c))) (\(b,(a,c)) -> (a,(b,c))) . seconding (Control.Lens.from (pry name))
- -- Λ review consName ('z',example)
- -- Person {_name = "zBob", _age = 55}
- --
- -- Λ preview consName example
- -- Just ('B',Person {_name = "ob", _age = 55})
Add Comment
Please, Sign In to add comment