Created
August 30, 2015 13:53
-
-
Save mbertheau/3fef571a1a5391387a75 to your computer and use it in GitHub Desktop.
What's this in clojure?
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
def add_net_and_tax(discounts): | |
discounts = map(lambda discount: assoc(discount, 'net', round(discount['gross'] / (1 + tax_rate))), | |
discounts) | |
discounts = map(lambda discount: assoc(discount, 'tax', discount['gross'] - discount['net']), | |
discounts) | |
return discounts |
(defn add-net-and-tax [discounts]
(map (fn [{:keys [gross] :as discount}]
(let [net (/ gross (inc tax-rate))]
(assoc discount :net net :tax (- gross net))))
discounts))
(defn add-net-and-tax [discounts]
(map #(as-> % discount
(assoc discount :net (/ (:gross discount) (inc tax-rate)))
(assoc discount :tax (- (:gross discount) (:net discount))))
discounts))
Hmm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this perhaps: