clara

http://www.clara-rules.org/
nick 2020-06-21T16:00:26.153400Z

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.