Skip to content

Instantly share code, notes, and snippets.

@guilespi
Last active August 29, 2015 13:58
Show Gist options
  • Save guilespi/10035399 to your computer and use it in GitHub Desktop.
Save guilespi/10035399 to your computer and use it in GitHub Desktop.
(defn validate-mappings
"Validates each mapped import is for an
existent field in the specified company"
[fields headers mappings]
(letfn [(found? [list element] (< (.indexOf list element) 0))]
(filter (fn [[header field]]
(or (found? headers header)
(found? fields field)))
mappings)))
;mappings is a map from csv header to schema field {"header" "db field"}
;header is a list of header field names ["h1" "h2" "h3"]
;fields is a list of db field names ["f1" "f2 "f3"]
@paraseba
Copy link

paraseba commented Apr 7, 2014

It's weird that you use (nth % 0) instead of first, presumably for performance reasons, but then you fail to type hint list in maps? Also, why partial? Why not just (comp name #(nth % 0)) Where you trying to partial nth, then realized you needed to bind the second argument instead of the first one and finally forgot to delete partial?

(keep #(when condition %) foo)   =   (filter #condition foo)

I'd make maps? return boolean and take the element, also rename header function argument to headers then

;; i find the following much easier to read
(filter (fn [[header field]]
          (or (maps? headers header)
              (maps? fields field))
        mappings) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment