Skip to content

Instantly share code, notes, and snippets.

@krisleech
Last active December 12, 2017 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/54d58b722fd294576e51f7514b51567f to your computer and use it in GitHub Desktop.
Save krisleech/54d58b722fd294576e51f7514b51567f to your computer and use it in GitHub Desktop.
Clojure map->vector
(def data
'({:comments "asd"
:expenditure 123.00M
:id 1
:ukcrc_category "Congenital Disorders,"
:year 2017}
{:comments nil
:expenditure 12.00M
:id 2
:ukcrc_category "Cardiovascular"
:year 2017}))
;; convert to collection, however we only want some keys...
(map vals data) ;; ((1 2017 "Congenital Disorders," 123.00M "asd") (2 2017 "Cardiovascular" 12.00M nil))
;; use first record to find out how...
(def rec (first data)) ;; {:comments "asd" :expenditure 123.00M :id 1 :ukcrc_category "Congenital Disorders," :year 2017}
;; works, just the id and comment keys...
(into [] [(:id rec) (:comments rec)]) ;; [1 "asd"]
;; use on whole collection...
(map #(into [] [(:ukcrc_category %) (:expenditure %)]) data)
;; or an alternative
(map (juxt :ukcrc_category :expenditure) data)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment