Skip to content

Instantly share code, notes, and snippets.

@dlikhten
Created July 19, 2011 21:35
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 dlikhten/1093784 to your computer and use it in GitHub Desktop.
Save dlikhten/1093784 to your computer and use it in GitHub Desktop.
(defn map-select [row selector]
(apply str (concat (interpose "\t" (selector row)) "\n")))
(defn tsv [rows]
(let [header (map-select (first rows) keys)
rows (apply str (for [row rows]
(map-select row vals)))]
(str header rows)))
; => (def p [{"a" 34 "b" 234 "c" 234} {"a" 234 "b" 234 "c" 24}])
; => (tsv p)
; => "a\tb\tc\n34\t234\t234\n234\t234\t24\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment