Last active
October 21, 2015 21:10
-
-
Save slipset/2c96d5b2bea6a87f57cd to your computer and use it in GitHub Desktop.
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
;; | |
;; When refactoring this kind of stuff, I tend to create functions to transform one of the items | |
;; This way, the threading stuff doesn't get to complicated. | |
;; | |
(defn ->sku-name-type [product] | |
(let [type (:type product)] | |
(->> product | |
:variations | |
(map val) | |
(map (partial merge {:type type}))))) | |
(defn available-stock [availability tuple] | |
(->> tuple | |
:sku | |
str | |
keyword | |
(get availability) | |
(merge tuple))) | |
(defn low-on-stock [hardwareCatalog availability treshold] | |
(->> hardwareCatalog | |
(vals) | |
(mapcat ->sku-name-type) | |
(map (partial available-stock availability)) | |
(filter #(> treshold (:availableQuantity %))) | |
(sort-by :name))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot, Erik! This is really much nicer. I have modified the blog post to point to your version.