Oldes / Rebol-wishes

Repository for keeping Rebol related wishes out of issues
0 stars 0 forks source link

KEEP-EACH function #44

Open Siskin-Bot opened 4 years ago

Siskin-Bot commented 4 years ago

Submitted by: BrianH

KEEP-EACH would be the inverse of REMOVE-EACH: Values would be kept if the condition evaluates to true. As such, it could be a simple mezzanine wrapper for REMOVE-EACH.

Suggested by Gregg in a Oldes/Rebol-issues#1718 comment. Code below. The Oldes/Rebol-issues#539 problem applies.

keep-each: func [
    "Removes values for each block that returns FALSE. Returns remove count."
    'word [get-word! word! block!] "Word or block of words to set each time (local)"
    data  [series!] "Series to traverse (modified)"
    body  [block!]  "Block to evaluate (return TRUE to keep)"
][
    remove-each (word) data reduce [:not :do body]
]

Imported from: CureCode [ Version: alpha 109 Type: Wish Platform: All Category: Mezzanine Reproduce: Always Fixed-in:none ] Imported from: https://github.com/rebol/rebol-issues/issues/1733

Comments:

Rebolbot commented on Nov 1, 2010:

Submitted by: Carl

Do we think it's worth-while adding?

It's the same as:

remove-each word series [not condition]

That's not a big difference. Really it comes down to if we think the abstraction of the KEEP word is of benefit. I'm borderline on it.


Rebolbot commented on Nov 2, 2010:

Submitted by: Gregg

I find it useful, though I won't say it's necessary. It makes the intent clearer than the double negative remove+not approach.

Why did you choose to have a negative filter option initially?


Rebolbot added the Type.wish on Jan 12, 2016