Skip to content

clojure.core/update

View this page on ClojureDocs

Type: function Added: Clojure 1.7 Examples: 10 Runnable: 6
([m k f] [m k f x] [m k f x y] [m k f x y z] [m k f x y z & more])

'Updates' a value in an associative structure, where k is a key and f is a function that will take the old value and any supplied args and return the new value, and returns a new structure. If the key does not exist, nil is passed as the old value.

Examples

by hiteki on
by egracer on . May have evaluation errors.
by G1enY0ung on
by statcompute on
by aarkerio on
by gloorfindel on . May have evaluation errors.
by huahaiy on
by rogefm on
by mars0i on . May have evaluation errors.
by lpasz on . May have evaluation errors.

Note by alper

But how do you do a pure update idiomatically? So update one value for another?

Note by Crowbrammer

To the previous note (alper), you are looking for assoc.

Note by earthfail

in clojure 1.11 there is an update-vals and update-keys to apply function for all values or all keys respectively

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.