I have a list [String] the task ist to remove those elements in the list, which have \"q\" or \"p\" and then capitalize all letters in the list with toUpper.
What I
I know, that toUpper in this line of code gets a list as value and therefore it can't work, but know how to go a level down into the list and the apply map toUpper.
Use (map . map)
instead of map
.
n.b. (map . map) toUpper
is the same as map (map toUpper)
as suggested by the other answers. I mention it because, personally, I find it clearer: it looks more like it is going down two levels to apply toUpper
. (You may not be familiar with the function composition operator (.)
, look it up or ask about it if you need to.)
Other functions with a similar type ((a -> b) -> something a -> something b
), such as fmap
, Data.Map.map
, first
and second
, can be combined with each other and with map
in a similar way.
Perhaps you don't find (map . map) toUpper
clearer than map (map toUpper)
; fair enough.