Last active
March 17, 2022 07:11
-
-
Save ahaxu/e27419f851648378e6997a83726dbf8c to your computer and use it in GitHub Desktop.
How useful of monoid is
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
-- How Monoids are useful in Programming? | |
-- credit to https://www.youtube.com/watch?v=BovTQeDK7XI | |
module XMain where | |
import Data.Char | |
import Data.Monoid | |
import Data.Foldable | |
isValid :: Char -> Bool | |
isValid = getAll . foldMap (All .) predicates | |
where | |
predicates = [isAlpha, isLower] | |
isValid' :: Char -> Bool | |
isValid' = getAll . fold mPredicates | |
where | |
predicates = [isAlpha, isLower] | |
mPredicates = map (All .) predicates | |
-- using sequence | |
isValid'' :: Char -> Bool | |
isValid'' = and . sequence [isAlpha, isLower] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment