Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created March 14, 2018 03:49
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 puffnfresh/8323d95a156f84fa3aa0e34cc63e7875 to your computer and use it in GitHub Desktop.
Save puffnfresh/8323d95a156f84fa3aa0e34cc63e7875 to your computer and use it in GitHub Desktop.
Prism' as a smart constructor
module Example (Example, example) where
import Data.Functor (($>))
import Control.Lens (Prism', prism')
import Control.Monad (guard)
data Example
= Example String
deriving (Eq, Ord, Show)
example :: Prism' String Example
example =
prism' f g
where
f (Example a) =
a
g s =
guard (even $ length s) $> Example s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment