Last active
July 6, 2016 17:06
-
-
Save afternoon/c25bac6712f7e67d810307fdd5d9e13e to your computer and use it in GitHub Desktop.
Map a function over a CSV file in Clojure
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
(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*))) |
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
(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