Skip to content

Instantly share code, notes, and snippets.

@sirlensalot
Created April 14, 2016 00:30
Show Gist options
  • Save sirlensalot/f46a91233eee0184c115692df8027f11 to your computer and use it in GitHub Desktop.
Save sirlensalot/f46a91233eee0184c115692df8027f11 to your computer and use it in GitHub Desktop.
Recover Cons in a newtype
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