A function that checks if all vowels in a string are uppercase
1 answer
You can use notElem
and all
, for example:
check :: String -> Bool
check = all (\e -> e `notElem` ['a', 'e', 'i', 'o', 'u'])
Here's an explanation:
-
(\e -> e notElem ['a', 'e', 'i', 'o', 'u'])
is a function that takese
and returns whether it is not a lowercase vowel element. -
all
takes a. a predicate that converts elements to boolean and b. an array of these elements and returns whether the predicate is true for all elements in the array.
Another thing that might help is to note that this is written using dot notation , but this is equivalent to
check s = all (\e -> e `notElem` ['a', 'e', 'i', 'o', 'u']) s
+4
source to share