Created
April 14, 2016 00:30
-
-
Save sirlensalot/f46a91233eee0184c115692df8027f11 to your computer and use it in GitHub Desktop.
Recover Cons in a newtype
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
newtype Ledger a = Ledger { _lEntries :: Seq a } | |
deriving (Eq,Show,Generic,Monoid) | |
makeLenses ''Ledger | |
instance Cons (Ledger a) (Ledger a) a a where | |
_Cons = prism (\(a,s) -> over lEntries (review _Cons . (a,)) s) $ | |
\s -> case firstOf _Cons (view lEntries s) of | |
Nothing -> Left mempty | |
(Just (a,as)) -> Right (a,set lEntries as s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment