Forked from dchelimsky/gist:682310d2bc9826357911
Last active
August 29, 2015 14:22
-
-
Save metasoarous/20454f412ac4c62bae58 to your computer and use it in GitHub Desktop.
Sketching out semantic-csv sniffer
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
diff --git a/src/semantic_csv/core.clj b/src/semantic_csv/core.clj | |
index bfb3972..6f780cb 100644 | |
--- a/src/semantic_csv/core.clj | |
+++ b/src/semantic_csv/core.clj | |
@@ -213,6 +213,19 @@ | |
;; pipeline. | |
+;; input - lazy seq of rows | |
+;; out - map of col-names to casting-fns | |
+;; optional args - n-lines | |
+;; default-casting-fn | |
+;; (cast-with-sniffer {:n-lines 20 :default str :overrides {:col-name fn}} csv-data) | |
+;; (->> csv-data | |
+;; (map x ...) | |
+;; (tranduce transducing-fn ...) | |
+;; (sniff {:n-lines 20 :default str :overrides {:col-10 int}})) | |
+(defn sniff ) | |
+(as-> coll xs | |
+ (map f xs) | |
+ (filter #(thing with xs) xs)) | |
;; <br /> | |
;; ## except-first | |
@@ -252,6 +265,16 @@ | |
;; <br/> | |
;; ## process | |
+ (def foo (comp | |
+ remove-comments | |
+ mappify | |
+ (cast-with {:this #(Integer/parseInt %)}) | |
+ doall)) | |
+ | |
+(with-open [in-file (io/reader "test/test.csv")] | |
+ (transduce foo (csv/parse-csv in-file)) | |
+) | |
+ | |
(defn process | |
"This function wraps together the most frequently used input processing capabilities, | |
controlled by an `opts` hash with opinionated defaults: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment