Created
November 25, 2018 13:00
-
-
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)
This file contains 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
{: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"}}} |
This file contains 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 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