Created
September 22, 2022 07:22
-
-
Save rotaliator/499206c151561f9eae66e11abb04f3b4 to your computer and use it in GitHub Desktop.
Convert list of map to data table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn maps-to-table | |
([labels list-of-maps] | |
(maps-to-table labels list-of-maps true)) | |
([labels list-of-maps with-headers?] | |
(let [header (when with-headers? [(mapv name labels)]) | |
data (mapv (apply juxt labels) list-of-maps)] | |
(if with-headers? | |
(concat header data) | |
data)))) | |
(comment | |
(maps-to-table [:col1 :col2] | |
[{:col1 "val1-col1" :col2 "val1-col2" :unused "not-relevant"} | |
{:col1 "val2-col1" :col2 "val2-col2"}]) | |
;; => (["col1" "col2"] | |
;; ["val1-col1" "val1-col2"] | |
;; ["val2-col1" "val2-col2"]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment