Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created July 21, 2020 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/a7a92d31d701848acb17f1617e07dba6 to your computer and use it in GitHub Desktop.
Save tonymorris/a7a92d31d701848acb17f1617e07dba6 to your computer and use it in GitHub Desktop.
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data These a b =
This a
| That b
| Both a b
deriving (Eq, Show)
makePrisms ''These
is :: APrism s t a b -> s -> Bool
is p = not . isn't p
-- can this be written "more neatly", without the duplication...
isThisOrThat :: These a b -> Bool
isThisOrThat t = is _This t || is _That t
-- like this, except in this case, the type has changed
isThisOrThat' :: These a a -> Bool
isThisOrThat' t = any (`is` t) [_This, _That]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment