Skip to content

Instantly share code, notes, and snippets.

@juergenhoetzel
Created September 25, 2010 10:50
Show Gist options
  • Save juergenhoetzel/596728 to your computer and use it in GitHub Desktop.
Save juergenhoetzel/596728 to your computer and use it in GitHub Desktop.
(defn mapmap
"Return a new map, mapping keys to (keyfn key) and mapping values to
(valfn val)"
([valfn map]
(mapmap identity valfn map))
([keyfn valfn map]
(persistent! (reduce
(fn [c [k v]] (assoc! c (keyfn k) (valfn v)))
(transient {})
map))))
@juergenhoetzel
Copy link
Author

@juergenhoetzel
Copy link
Author

Performance using persistant data only:

user> (time ((mapmap identity identity bigmap) :noexist))
"Elapsed time: 513.812028 msecs"

Transients can really speed-up:
user> (time ((mapmap identity identity bigmap) :noexist))
"Elapsed time: 301.332019 msecs"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment