[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.3.2 Selection and searching in collection

Generic function: find pred coll
Applies pred for each element of a collection coll until pred returns a true value. Returns the element on which pred returned a true value, or #f if no element satisfies pred.

If coll is a sequence, it is guaranteed that pred is applied in order. Otherwise the order of application is undefined. Returns a list of elements of collection coll that satisfies the predicate pred. If the collection is a sequence, the order is preserved in the result.

 
(filter char-upper-case? "Hello, World")
  => (#\H #\W)
(filter even? '#(1 2 3 4)) => (2 4)

Generic function: filter-to class pred coll
Same as filter, but the result is returned as a collection of class class.

 
(filter-to <vector> even? '#(1 2 3 4)) => #(2 4)
(filter-to <string> char-upper-case? "Hello, World") 
  => "HW"

Generic function: remove pred coll
Returns a list of elements of collection coll that does not satisfy the predicate pred. If the collection is a sequence, the order is preserved in the result.

 
(remove char-upper-case? "Hello, World")
  => (#\e #\l #\l #\o #\, #\space #\o #\r #\l #\d)
(remove even? '#(1 2 3 4)) => (1 3)

Generic function: remove-to class pred coll
Same as remove, but the result is returned as a collection of class class.

 
(remove-to <vector> even? '#(1 2 3 4)) => #(1 3)
(remove-to <string> char-upper-case? "Hello, World") 
  => "ello, orld"

Generic function: partition pred coll
Does filter and remove the same time. Returns two lists, the first consists of elements of the collection coll that satisfies the predicate pred, and the second consists of elements that doesn't.

 
(partition char-upper-case? "PuPu")
  => (#\P #\P) and (#\u #\u)
(partition even? '#(1 2 3 4))
  => (2 4) and (1 3)

Generic function: partition-to class pred coll
Same as partition, except the results are returned in the collections of class class.

 
(partition-to <string> char-upper-case? "PuPu")
  => "PP" and "uu"
(partition-to <vector> even? '#(1 2 3 4))
  => #(2 4) and #(1 3)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html