Created
January 22, 2010 02:24
-
-
Save francoisdevlin/283450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns user) | |
| (defn assoc-in | |
| "Associates a value in a nested associative structure, where ks is a | |
| sequence of keys and v is the new value and returns a new nested structure. | |
| If any levels do not exist, hash-maps will be created." | |
| [m [k & ks] v] | |
| (if ks | |
| (assoc m k (assoc-in (get m k) ks v)) | |
| (assoc m k v))) | |
| (defn assoc-in-2 | |
| "Forces a sorted map" | |
| [m [k & ks] v] | |
| (if ks | |
| (assoc m k (assoc-in-2 (get m k (sorted-map)) ks v)) | |
| (assoc m k v))) | |
| (defn assoc-in-with | |
| "supply a default-map" | |
| [m default-map [k & ks] v] | |
| (if ks | |
| (assoc m k (assoc-in-as (get m k default-map) default-map ks v)) | |
| (assoc m k v))) | |
| (defn assoc-in-empty | |
| "Same type as top" | |
| [m ks v] | |
| (assoc-in-by m (empty m) ks v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment