Created
March 14, 2018 03:49
-
-
Save puffnfresh/8323d95a156f84fa3aa0e34cc63e7875 to your computer and use it in GitHub Desktop.
Prism' as a smart constructor
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
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