Created
March 27, 2023 10:08
-
-
Save kephas/f59f9ed60a89348f3d652193959deba2 to your computer and use it in GitHub Desktop.
Alternative to early return in Functional Programming
This file contains hidden or 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
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