Skip to content

Instantly share code, notes, and snippets.

@prozz
Last active December 30, 2015 02:19
Show Gist options
  • Save prozz/7761701 to your computer and use it in GitHub Desktop.
Save prozz/7761701 to your computer and use it in GitHub Desktop.
clojure adventures
how to get from [{:text "AAA", :code "0011"}] to {11 {:text "AAA", :code "0011"}}
note that key in result is made with use of following function:
=> (code->int "00123")
123
=> (def t [{:code "0011" :text "AAA"}])
[{:text "AAA", :code "0011"}]
=> (into {} (map identity t))
{:text "AAA", :code "0011"}
=> (into {} (map :code t))
ClassCastException java.lang.Character cannot be cast to java.util.Map$Entry clojure.lang.ATransientMap.conj (ATransientMap.java:44)
=> (into {} (map (juxt :code) t))
IllegalArgumentException Vector arg to map conj must be a pair clojure.lang.ATransientMap.conj (ATransientMap.java:37)
=> (into {} (map (juxt :code identity) t))
{"0011" {:text "AAA", :code "0011"}}
=> (into {} (map (juxt (comp code->int :code) identity) t))
{11 {:text "AAA", :code "0011"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment