This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-21
Channels
- # announcements (3)
- # aws (11)
- # babashka (5)
- # beginners (116)
- # cider (30)
- # clara (1)
- # clj-kondo (15)
- # clojure (17)
- # clojure-dev (9)
- # clojure-europe (2)
- # clojure-italy (1)
- # clojure-uk (3)
- # clojurescript (9)
- # conjure (3)
- # duct (22)
- # exercism (1)
- # fulcro (8)
- # graalvm (5)
- # graphql (3)
- # helix (3)
- # joker (3)
- # kaocha (2)
- # off-topic (9)
- # pathom (4)
- # re-frame (1)
- # rum (6)
- # shadow-cljs (81)
- # sql (6)
- # xtdb (9)
Hey all I was wondering if there is a simpler way to rewrite this?
(defrule calc-total-sum
[?total1 <- (acc/reduce-to-accum (fn [previous value]
(+ previous (get-amount value)))
0
) :from [Record1]]
[?total2 <- (acc/reduce-to-accum (fn [previous value]
(+ previous (get-amount value)))
0
) :from [Record2]]
=>
(insert! (->TotalAmount (+ ?total1 ?total2))))
I have lots of record types like RecordN(in this simplified example) defrecord-s and all of them implement the same protocol(`get-amount` func)
I'm trying to get the total amount for all those record types.
Ideally this would be just a single reduce-to-accum with :from [Record1 Record2 ...]
or :from [[Record1] [Record2] [...]]
but it doesn't seem to work.