Except except¶
Returns the items in the first collection that are not in the second collection.
Basic Usage¶
↪ (except [1 2 3 4 5] [2 4])
[1 3 5]
↪ (except ['a 'b 'c] ['a 'c])
[b]
↪ (except [1 2 3] [5 6 7])
[1 2 3]
Scalar Except¶
Handling Duplicates¶
Info
- Returns elements from the first collection that don't exist in the second
- Can use a scalar as the second argument to remove a single value
- Duplicates are preserved in the result (unlike
distinct) - If an element appears multiple times in the first collection but is excluded, all occurrences are removed
- Empty collections are handled gracefully:
(except [] x)returns[],(except x [])returnsx
Tip
Use except to filter out unwanted values from a collection while preserving duplicates