Skip to content

Instantly share code, notes, and snippets.

@ahaxu
Last active March 17, 2022 07:11
Show Gist options
  • Save ahaxu/e27419f851648378e6997a83726dbf8c to your computer and use it in GitHub Desktop.
Save ahaxu/e27419f851648378e6997a83726dbf8c to your computer and use it in GitHub Desktop.
How useful of monoid is
-- 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