Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- asNewtypeIf ::
- (a -> b) -- Type constructor
- -> (a -> Bool) -- Constraint for newtype
- -> a -- Unwrapped value
- -> Maybe b -- Maybe wrapped value
- asNewtypeIf constructor predicate input
- | predicate input = Just (constructor input)
- | otherwise = Nothing
- --
- newtype ShortString = ShortString String
- deriving Show
- makeShortString :: String -> Maybe ShortString
- makeShortString = ShortString `asNewtypeIf` isValidShortString
- where
- isValidShortString = (<= 3) . length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement