logoalt Hacker News

seanw444yesterday at 10:05 PM2 repliesview on HN

I've never run into a generic "filter" function which keeps only the non-matching elements.


Replies

jdougantoday at 12:17 AM

Smalltalk has #reject: which does that. You could, of course, just wrap a not around the test in the closure, but sometimes reject with a well-named predicate is easier to read.

bsnpApproved := tvShows reject: [ :eachShow | eachShow hasNaughtyContent ].

dreamcompilertoday at 1:00 AM

Common Lisp's filter is remove-if which works this way.

(It also has remove-if-not but that's deprecated and if you use it your code smells.)

show 1 reply