This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-01
Channels
- # aleph (6)
- # announcements (37)
- # aws (1)
- # beginners (67)
- # calva (9)
- # clerk (5)
- # clj-kondo (3)
- # clojure (19)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (36)
- # clojure-uk (5)
- # clojuredesign-podcast (7)
- # clojurescript (28)
- # datomic (9)
- # emacs (8)
- # figwheel-main (4)
- # fulcro (6)
- # hyperfiddle (19)
- # integrant (4)
- # java (9)
- # lsp (131)
- # malli (9)
- # missionary (85)
- # off-topic (13)
- # pathom (3)
- # polylith (11)
- # releases (1)
- # sci (4)
- # shadow-cljs (7)
- # specter (2)
- # vscode (1)
- # xtdb (2)
what's a better way to write this using paths? basically trying to sum the values taking into account nil.
(def data {:a [{:val 1} {:val 2}]
:b [{:val 4} {:val nil}]
:c [{:val 7} {:val 8}]})
(sp/transform [sp/MAP-VALS] #(->> % (map :val) (filter number?) (apply +)) data)
=> {:a 3, :b 4, :c 15}
this is more efficient (transform [MAP-VALS (view #(select [ALL :val some?] %))] #(reduce + 0 %) data)
🙏 1