Skip to content

Instantly share code, notes, and snippets.

@seancorfield

seancorfield/README.md

Last active Jan 6, 2020
Embed
What would you like to do?
map-vals and map-keys

Running this code:

clj -Sdeps '{:deps 
             {seancorfield/map-utils 
              {:git/url "https://gist.github.com/seancorfield/6e8dd10799e9cc7527da5510c739e52f"
               :sha "cfde3c2c83379e93ab1a49752611ae663008129f"}}}'

That starts a REPL:

user=> (require '[map-utils :refer [map-vals map-keys]])
nil
user=> (map-vals inc {:a 1 :b 2})
{:b 3, :a 2}
user=>
{:paths ["."]}
(ns map-utils)
(defn map-vals [f m] (reduce-kv (fn [m k v] (assoc m k (f v))) {} m))
(defn map-keys [f m] (reduce-kv (fn [m k v] (assoc m (f k) v)) {} m))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment