Skip to content

Instantly share code, notes, and snippets.

@kephas
Created March 27, 2023 10:08
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 kephas/f59f9ed60a89348f3d652193959deba2 to your computer and use it in GitHub Desktop.
Save kephas/f59f9ed60a89348f3d652193959deba2 to your computer and use it in GitHub Desktop.
Alternative to early return in Functional Programming
checkUserForPromotion :: User -> Either String User
checkUserForPromotion user =
case (user.age > 18, user.country, length user.purchases > 5) of
(True, France, True) -> Right (user { status = Vip })
(False, _, _) -> Left "trop jeune"
(True, _, False) -> Left "pas assez d'achats"
(True, _, True) -> Left "pas français"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment