Next: srfi sets-and-bags copy, Previous: srfi sets-and-bags whole, Up: srfi sets-and-bags [Index]
Apply proc to each element of set in arbitrary order and
return a newly allocated set, created as if by (set
comparator)
, which contains the results of the applications. For
example:
(set-map string-ci-comparator symbol->string (set eq-comparator 'foo 'bar 'baz)) ≡ (set string-ci-comparator "foo" "bar" "baz")
Note that, when proc defines a mapping that is not 1:1, some of the mapped objects may be equivalent in the sense of comparator’s equality predicate, and in this case duplicate elements are omitted as in the set constructor. For example:
(set-map integer-comparator (lambda (x) (quotient x 2)) (set integer-comparator 1 2 3 4 5)) ≡ (set integer-comparator 0 1 2)
If the elements are the same in the sense of eqv?
, it is
unpredictable which one will be preserved in the result.
Apply proc to each element of bag in arbitrary order and
return a newly allocated bag, created as if by (bag
comparator)
, which contains the results of the applications. For
example:
(bag-map string-ci-comparator symbol->string (bag eq-comparator 'foo 'bar 'baz)) ≡ (bag string-ci-comparator "foo" "bar" "baz") (list-sort < (bag->list (bag-map integer-comparator (lambda (x) (quotient x 2)) (bag integer-comparator 1 2 3 4 5)))) ⇒ (0 1 1 2 2)
Apply proc to set or bag in arbitrary order, discarding the returned values. Return unspecified results.
Invoke proc on each member of set or bag in arbitrary order, passing the result of the previous invocation as a second argument. For the first invocation, nil is used as the second argument. Return the result of the last invocation, or nil if there was no invocation.
(import (vicare) (srfi :113) (srfi :114)) (list-sort < (set-fold (lambda (elm nil) (cons elm nil)) '() (set fixnum-comparator 1 2 3))) ⇒ (1 2 3) (list-sort < (bag-fold (lambda (elm nil) (cons elm nil)) '() (bag fixnum-comparator 1 2 2 3))) ⇒ (1 2 2 3)
Return a newly allocated set or bag with the same comparator as set or bag, containing just the elements of set or bag that satisfy predicate.
Like set-filter
and bag-filter
but they are permitted to
mutate and return set or bag rather than allocating a new
set or bag.
Return a newly allocated set or bag with the same comparator as set or bag, containing just the elements that do not satisfy predicate.
Like set-remove
and bag-remove
but they are permitted to
mutate and return set or bag rather than allocating a new
set or bag.
Return two values:
Usage example:
(import (vicare) (srfi :113) (srfi :114)) (receive (in out) (set-partition (lambda (elm) (<= 2 elm)) (set fixnum-comparator 1 2 2 3)) (values (set->list in #t) (set->list out #t))) ⇒ (2 3) (1) (receive (in out) (bag-partition (lambda (elm) (<= 2 elm)) (bag fixnum-comparator 1 2 2 3)) (values (bag->list in #t) (bag->list out #t))) ⇒ (2 2 3) (1)
Like set-partition
and bag-partition
but they are
permitted to mutate and return set or bag rather than
allocating a new set or bag.
Next: srfi sets-and-bags copy, Previous: srfi sets-and-bags whole, Up: srfi sets-and-bags [Index]