Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Last active July 9, 2020 06:23
Show Gist options
  • Save tonymorris/6f38d27a197e5b8fc9e9b0d041c1a344 to your computer and use it in GitHub Desktop.
Save tonymorris/6f38d27a197e5b8fc9e9b0d041c1a344 to your computer and use it in GitHub Desktop.
{-# LANGUAGE LambdaCase #-}
import Control.Lens
data Blah a =
Blah1 a
| Blah2 a
| BlahS String
deriving (Eq, Show)
isBlah1orS :: Blah a -> Bool
isBlah1orS b = not (isn't _Blah1 b || isn't _BlahS b)
_Blah1 :: Prism' (Blah a) a
_Blah1 =
prism'
Blah1
(\case
Blah1 a -> Just a
_ -> Nothing
)
_Blah2 :: Prism' (Blah a) a
_Blah2 =
prism'
Blah2
(\case
Blah2 a -> Just a
_ -> Nothing
)
_BlahS :: Prism' (Blah a) String
_BlahS =
prism'
BlahS
(\case
BlahS s -> Just s
_ -> Nothing
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment