One way to implement map-invert #51

Closed
wants to merge 1 commit into from

2 participants

@pokle

Hi there,

Here's an example for reduce-kv.

Cheers,
Tushar

@arrdem

Looks good! Thanks! I'm reworking the examples system prior to 0.3.0, so I'm gonna sit on this along with the other outstanding PR until I can incorperate them as real example modules that'll never need to get reworked.

@arrdem arrdem added this to the 0.3.1 milestone Jul 24, 2014
@miner miner commented on the diff Aug 1, 2014
_includes/1.6.0/clojure.core/reduce_DASH_kv/examples.md
@@ -1,3 +1,8 @@
{% include 1.5.0/clojure.core/reduce_DASH_kv/examples.md %}
-[Please add examples!](https://github.com/arrdem/grimoire/edit/master/_includes/1.6.0/clojure.core/reduce_DASH_kv/examples.md)
+Example: Use reduce-kv to invert a map
+
+ user=> (reduce-kv (fn [accum k v] (conj accum {v k})) {} {:a 1 :b 2 :c 3 :d 3})
@miner
miner added a note Aug 1, 2014

It would be better to use assoc to add to the accum map.

(reduce-kv (fn [accum k v] (assoc accum v k)) {} {:a 1 :b 2 :c 3 :d 3})
@arrdem
arrdem added a note Aug 1, 2014

This file no longer exists as of 0.3.0

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

The file targeted by this patch no longer exists as of 0.3.0. Please submit a new PR adding a new example file by clicking the "add example" link on the symbol's page.

@arrdem arrdem closed this Aug 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment