Josh Roberts
Josh Roberts

Reputation: 892

Filter by letters or spaces in haskell

I'm trying to filter everything from a string other than letters or spaces by combining isLetter and isSpace conditions, but this didn't work.

normalise = filter (\x -> (Char.isLetter || Char.isSpace))

Is there a way to filter for one condition or another?

Upvotes: 2

Views: 909

Answers (2)

Jeremy List
Jeremy List

Reputation: 1766

You can also do it using combinators like this:

import Control.Arrow
normalise = filter ((Char.isLetter &&& Char.isSpace) >>> uncurry (||))

Upvotes: 0

Piotr Miś
Piotr Miś

Reputation: 981

You are missing function application in your lambda. It should be:

normalise = filter (\x -> Char.isLetter x || Char.isSpace x)

Upvotes: 7

Related Questions