-
-
Save stungeye/adf3134a819004058dad to your computer and use it in GitHub Desktop.
| (ns eds-lookup.core | |
| (:gen-class)) | |
| (require '[clj-yaml.core :as yaml] | |
| '[clojure-csv.core :as csv] | |
| '[clojure.string :as str]) | |
| (def new-locations (yaml/parse-string (slurp "locations.yml"))) | |
| (def eds-locations (csv/parse-csv (slurp "eds-locations.csv"))) | |
| (defn new-location [location-code] | |
| (new-locations (keyword (str/lower-case location-code)))) | |
| (defn update-location-vector [location-vector] | |
| (let [[code _ facet limiter] location-vector] | |
| [code (new-location code) facet limiter])) | |
| (defn update-eds-locations [location-table] | |
| (let [[header & table] eds-locations] | |
| (cons header (map update-location-vector table)))) | |
| (defn -main [& args] | |
| (spit "output" (csv/write-csv (update-eds-locations eds-locations)))) |
Oh, thanks - yeah, that's much better. I get what you've done. That makes a lot of sense.
I really felt the lack of a test in this case - I need to start getting into TDD with clojure. I also (for the first time) felt the lack of syntax tools, as in that Sublime video.
Cheers!
I just reread your refactor - it has the simplicity I knew I hadn't achieved with my attempt. In mine I could tell that it wasn't as clear as the Ruby version, which seemed strange, given what Clojure's like (it should be at least as clear), but with this everything is broken out and properly functional. This looks really good.
I did a poor man's TDD by running lein run && diff output output.golden where output.golden was your output.
I had to jump into the repl though on occasion, which I probably wouldn't have needed if I had written finer grain tests.
Changes:
-mainto allow forlein runlocationstonew-locationsfor clarity.get-in-locations [location-key]tonew-location [location-code]for clarity.update-eds-locationsto destructure the csv header from the table data.update-location-vectorto remove theif-letsince the header is no longer present.update-location-vectorto destructure thelocation-vectorand built new vector in place.