Skip to content

Instantly share code, notes, and snippets.

@afternoon
Last active July 6, 2016 17:06
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 afternoon/c25bac6712f7e67d810307fdd5d9e13e to your computer and use it in GitHub Desktop.
Save afternoon/c25bac6712f7e67d810307fdd5d9e13e to your computer and use it in GitHub Desktop.
Map a function over a CSV file in Clojure
(ns pairpeers.core
(:require [clojure.data.csv :as csv]))
(defn pair-with-first [[s & more]]
(map list (repeat s) more))
(defn rows->peers [rows]
(->> rows
(map pair-with-first)
(reduce concat)))
(defn -main [& args]
(->> (csv/read-csv *in*)
(rows->peers)
(csv/write-csv *out*)))
(defproject pairpeers "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [
[org.clojure/clojure "1.8.0"]
[org.clojure/data.csv "0.1.3"]]
:main pairpeers.core)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment