Skip to content

Instantly share code, notes, and snippets.

@mbertheau
Created August 30, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbertheau/3fef571a1a5391387a75 to your computer and use it in GitHub Desktop.
Save mbertheau/3fef571a1a5391387a75 to your computer and use it in GitHub Desktop.
What's this in clojure?
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
@broquaint
Copy link

Something like this perhaps:

(defn add-net-and-tax [discounts]
 (for [discount discounts]
   (let [gross (:gross disocount)
         net (/ gross (+ 1 tax_rate))]
     (assoc discount
       :net net
       :tax (- gross net)))))

@expez
Copy link

expez commented Aug 30, 2015

(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))

@mbertheau
Copy link
Author

(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