Reputation: 310
Let's say that I declare a variable in GHCI
let a = ["hello","goodbye","","sup","bye","hi","cat","dog"]
And I want to go about removing that pesky "" from the list. From my understanding, I should be able to use dropWhile to do so, like this
dropWhile null a
But this doesn't remove the pesky "". Why is this? How can I fix this issue?
Ah, now I understand. I completely misunderstood how dropWhile works. So then to make this question a little different - how do I remove blank entries in a list?
Upvotes: 1
Views: 830
Reputation: 33671
dropWhile
drops elements while given predicate is True
. null "hello"
is False
, so, it should'n drop anything.
You are probably looking for a filter
:
Prelude> filter (not . null) ["hello","goodbye","","sup","bye","hi","cat","dog"]
["hello","goodbye","sup","bye","hi","cat","dog"]
Upvotes: 10