I have a list like ["a","ab","abc", "abcd"]
How to get a list that only has the items which have a length > 2.
Means the result is ["abc","abcd"].
Natalie's answer is perfectly correct, but as an alternate form you could also write it as
filter ((> 2) . length) ["a", "ab", "abc", "abcd"]
Or with list comprehension as
[str | str <- ["a", "ab", "abc", "abcd"], length str > 2]
All three are equivalent
filter (\x -> length x > 2) ["a","ab","abc", "abcd"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With