Remove
This week’s IPM went spectacular. For the first time ever I didn’t fumble my way through the presentation. It also seems like the extra time I allocated for refactoring paid off. I’m still not sure if I have estimation fully down, but it is definitely getting better. Because estimations are so task specific it’s hard to know what ya don’t know… ya know?
Remove
remove
is actually a very easy function to understand and use, but it is one I didn’t realize existed until today. Any
time I’ve wanted to remove something from a collection I’ve used the filter
function. These two functions do the same
thing, except for one key difference.
The first argument to be passed into these functions (the filter conditions) filters out anything that evaluates to
false
that gets passed through the argument.
(filter even? [0 1 2 3 4 5 6 7 8 9])
=> (0 2 4 6 8)
The first argument in the remove function filters out anything that evaluates to true
.
(remove even? [0 1 2 3 4 5 6 7 8 9])
=> (1 3 5 7 9)
Before learning of the remove
function, any time I wanted to remove something, I would wrap the argument in a not
statement to get the result I wanted.
(filter #(not (even? %)) [0 1 2 3 4 5 6 7 8 9])
=> (1 3 5 7 9)
(This example may be a little dramatic, I’d just use odd?
here, but I wanted to make this simple for the
explanation’s sake).
While this certainly works, it’s unnecessary and much harder to read. It feels laughable now to look back and see how easy it was to get my intended results with the change of one word, but as I said before, it’s hard to know what ya don’t know… ya know?