Skip to content

Instantly share code, notes, and snippets.

@jorinvo
Created November 25, 2018 13:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorinvo/5926a0ac261a458f9b936cbb2e9cfc6b to your computer and use it in GitHub Desktop.
Save jorinvo/5926a0ac261a458f9b936cbb2e9cfc6b to your computer and use it in GitHub Desktop.
The Expressive C++17 Coding Challenge in Clojure (see https://words.steveklabnik.com/the-expressive-c-17-coding-challenge-in-rust-revisited)
{:deps {org.clojure/tools.cli {:mvn/version "0.3.7"}
org.clojure/data.csv {:mvn/version "0.1.4"}
semantic-csv {:mvn/version "0.2.1-alpha1"}}}
(ns main
(:require
[clojure.java.io :as io]
[clojure.tools.cli :refer [parse-opts]]
[clojure.data.csv :refer [write-csv]]
[semantic-csv.core :as csv])
(:gen-class))
(def cli-options
[["-f" "--filename CSVFILE"]
["-c" "--column-name COLUMN"]
["-r" "--replacement STRING"]
["-o" "--output-filename CSVFILE"]])
(defn -main [& args]
(let [{{:keys [filename column-name replacement output-filename]} :options} (parse-opts args cli-options)]
(with-open [reader (io/reader filename)
writer (io/writer output-filename)]
(->> (csv/parse-and-process reader :keyify false)
(map #(assoc % column-name replacement))
csv/vectorize
(write-csv writer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment