3 ms·
Why is `reject!` even a separate, and different implementation than `select!`? Perf reasons? Haskell's Data.List doesn't seem to even have a remove/reject. Clo
by sriharis 10y ago
Why is `reject!` even a separate, and different implementation than `select!`? Perf reasons?
Haskell's Data.List doesn't seem to even have a remove/reject. Clojure's remove is simply a complement of filter.
- yebyen 10y agoSame reason ruby has both "if" and "Unless", or capybara has .to_not as well as .not_to... there are times when the inverse expression is just more natural and less confusing. Rubocop, on the other hand against what I've just said, will tell you in almost every case that you might use Unless, or in agreement with what I think it is that You are saying here, the preferred idiom is to not use the inverse, and you should only say "unless" when what you meant to say is unambiguously !if. IOW sometimes you really mean reject
- dopamean 10y agoI don't think the commenter is asking why the method exists. But more why is it that the bug exists with reject! and not select!. Why the underlying implementations of those two very similar methods different?
- CGamesPlay 10y agoThey are identical (inverted) implementations as of ruby 2.3, so I think it was just an oversight.
- LyndsySimon 10y agoBecause it's Ruby. I've been using Ruby (in the context of Rails apps) for almost six months now, after a decade or so in mostly Python. Ruby is just "messy" in my opinion, and having the separate methods Array#select and Array#reject is just a single symptom of that. Another example is that something in Rails adds Array#fourth. I can't imagine a circumstance where using my_array.fourth is clearer than my_array[3].