Next: , Previous: , Up: srfi list spec   [Index]

2.2.5.7 Filtering and partitioning

Function: filter pred list
Function: filter! pred list

Return all the elements of list that satisfy predicate pred. The list is not disordered: elements that appear in the result list occur in the same order as they occur in list. The returned list may share a common tail with list. The dynamic order in which the various applications of pred are made is not specified.

```(filter even? '(0 7 8 8 43 -4)) => (0 8 8 -4)
```

`filter!` is the linear–update variant of `filter`. It is allowed, but not required, to alter the cons cells in list to construct the result lists.

Function: partition pred list
Function: partition! pred list

Partition the elements of list with predicate pred, and return two values: the list of in–elements and the list of out–elements. The list is not disordered: elements occur in the result lists in the same order as they occur in list. The dynamic order in which the various applications of pred are made is not specified. One of the returned lists may share a common tail with list.

```(partition symbol? '(one 2 3 four five 6))
=> (one four five)
(2 3 6)
```

`partition!` is the linear–update variant of `partition`. It is allowed, but not required, to alter the cons cells in list to construct the result lists.

Function: remove pred list
Function: remove! pred list

Return list without the elements that satisfy predicate pred:

```(lambda (pred list)
(filter (lambda (x)
(not (pred x)))
list))
```

The list is not disordered: elements that appear in the result list occur in the same order as they occur in list. The returned list may share a common tail with list. The dynamic order in which the various applications of pred are made is not specified.

```(remove even? '(0 7 8 8 43 -4)) => (7 43)
```

`remove!` is the linear–update variant of `remove`. It is allowed, but not required, to alter the cons cells in list to construct the result lists.

Next: , Previous: , Up: srfi list spec   [Index]