REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 16-Aug-2010 Edit History  

REBOL 3 Functions: remove-each

remove-each  word  data  body

Removes values for each block that returns true. Returns remove count. (Modifies)

Arguments:

word [word! block!] - Word or block of words to set each time (local)

data [series!] - The series to traverse

body [block!] - Block to evaluate (return TRUE to remove)

See also:

foreach   remove   map-each  

Description

The remove-each function is a high performance method of removing specific elements from a series. It is similar to foreach but will remove one or more values depending on the result of the evaluated block.

In this example, remove-each is used to remove all strings from the block:

values: [12 "abc" test 5 "de" 10:30]
remove-each value values [string? value]
probe values
[12 test 5 10:30]

Here, all integer values greater than 11 are removed:

values: [12 "abc" test 5 "de" 10:30]
remove-each value values [all [integer? value value > 11]]
probe values
["abc" test 5 "de" 10:30]

Multiple Elements

The remove-each function can be used on multiple elements, just as foreach does.

movies: [
     8:30 "Contact"      $4.95
    10:15 "Ghostbusters" $3.25
    12:45 "Matrix"       $4.25
]

foreach [time title price] movies [
    print [title "at" time "for" price]
    if price > $4.00 [print "removed" true]
]
Contact at 8:30 for $4.95
removed
Ghostbusters at 10:15 for $3.25
Matrix at 12:45 for $4.25
removed

This example also shows that the evaluated block may contain any other expressions as long as the last one returns true for removed values.

Also, notice here the way if is used for its return value.


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin