Last active
June 8, 2023 17:43
-
-
Save imsaravana369/6d10b50be1ba640812266e09847c7b10 to your computer and use it in GitHub Desktop.
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
import Data.Validation.Semigroup | |
type Person = {name :: String, age :: Int, email :: String} | |
validateName :: String -> V (Array String) String | |
validateName name = if null name | |
then invalid ["Name shouldn't be empty"] | |
else pure name | |
validateAge :: Int -> V (Array String) Int | |
validateAge age = if age < 0 | |
then invalid ["Age shouldn't be less than 0"] | |
else pure age | |
validateEmail :: String -> V (Array String) String | |
validateEmail email = if contains (Pattern "@") email | |
then pure email | |
else invalid ["Email ID should have @"] | |
validatePerson :: Person -> V (Array String) Person | |
validatePerson person = ado | |
name <- validateName person.name | |
age <- validateAge person.age | |
email <- validateEmail person.email | |
in {name, age, email} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment