Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This isn't a direct answer to your question, but one reason why a function like <code>update-in</code> could exist would be for efficiency&mdash;not just convenience&mdash;if it were able to update the value in the map "in-place". That is, rather than</p> <ul> <li>seeking the key in the map,</li> <li>finding the corresponding key-value tuple,</li> <li>extracting the value,</li> <li>computing a new value based on the current value,</li> <li>seeking the key in the map,</li> <li>finding the corresponding key-value tuple,</li> <li>and overwriting the value in the tuple or replacing the tuple with a new one</li> </ul> <p>one can instead imagine an algorithm that would omit the second search for the key:</p> <ul> <li>seek the key in the map,</li> <li>find the corresponding key-value tuple,</li> <li>extract the value,</li> <li>compute a new value based on the current value,</li> <li>and overwrite the value in the tuple</li> </ul> <p>Unfortunately, <a href="http://clojuredocs.org/clojure_core/clojure.core/update-in" rel="noreferrer">the current implementation of <code>update-in</code></a> does not do this "in-place" update. It uses <a href="http://clojuredocs.org/clojure_core/clojure.core/get" rel="noreferrer"><code>get</code></a> for the extraction and <a href="http://clojuredocs.org/clojure_core/clojure.core/assoc" rel="noreferrer"><code>assoc</code></a> for the replacement. Unless <code>assoc</code> is using some caching of the last looked up key and the corresponding key-value tuple, the call to <code>assoc</code> winds up having to seek the key again.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload