clojure-italy 2021-02-11

'giorno. una domanda di stile, come la vedete mixare threading macros?

(-> lots-of-maps
    (->> (filter beautiful-things)
         (sort-by :very-important-key))
    first
    :actual-important-key
    (or meaningful-default))

nay 👎 😬

quando proprio ho dovuto, ho usato (as->)

👍 1

vero, meno esoterico

Curious facts:

(as-> {:x "15.1" :y "84.2"} {:keys [x y] :as point}
  (update point :x #(Double/valueOf %))
  (update point :y #(Double/valueOf %))
  (assoc point :sum (+ x y))
  (assoc point :keys (keys point)))
;; {:x 15.1, :y 84.2, :sum 99.3, :keys (:x :y :sum)}

1. supporto per il destructuring 2. :sum dimostra che x e y sono stati sia processati che ri-destructurati