Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "Update-in" in Clojure?

Tags:

clojure

I'm trying to use Clojure's update-in function but I can't seem to understand why I need to pass in a function?

like image 707
yazz.com Avatar asked Jan 09 '11 21:01

yazz.com


1 Answers

update-in takes a function, so you can update a value at a given position depending on the old value more concisely. For example instead of:

(assoc-in m [list of keys] (inc (get-in m [list of keys])))

you can write:

(update-in m [list of keys] inc)

Of course if the new value does not depend on the old value, assoc-in is sufficient and you don't need to use update-in.

like image 94
sepp2k Avatar answered Sep 22 '22 03:09

sepp2k