chickadee » integer-map » fxmapping-update-max

fxmapping-update-min fxmap procprocedure
fxmapping-update-max fxmap procprocedure

The proc argument of fxmapping-update-min and -max is of type fixnum * (* → fxmapping) ([] → fxmapping) → * ….

Updates the association of fxmap with the least/greatest key k as follows. proc is invoked in tail context on k, its associated value, and two procedure arguments, replace and delete, and its values are returned. Invoking replace on a value v returns a fxmapping with the association (k, v) and all of fxmap's other associations. Invoking delete returns a fxmapping with all of the associations of fxmap, but without an association for k. It is an error if fxmap is empty.

Note that, in contrast to similar Scheme forms, proc is not required to tail-call one of delete or replace, and that fxmapping-update-min and -max simply return the results of invoking proc. Thus, the following is valid:

(fxmapping-update-min (fxmapping 0 'a 1 'b 2 'c)
                      (lambda (k v _r delete)
                        (values k v (fxmapping->alist (delete)))))
 ⇒ 0
   a
   ((1 . b) (2 . c))

Examples:

(fxmapping->alist
 (fxmapping-update-min (fxmapping -5 "phaser" -1 "tricorder")
                       (lambda (_ v replace delete)
                         (if (symbol? v)
                             (replace v)
                             (delete)))))
 ⇒ ((-1 . "tricorder"))

(fxmapping->alist
 (fxmapping-update-max (fxmapping -5 "phaser" -1 "tricorder")
                       (lambda (k v replace delete)
                         (if (and (negative? k) (string? v))
                             (replace (string-length v))
                             (delete)))))
 ⇒ ((-5 . "phaser") (-1 . 9))