I used reductions
to get the cumulative values as we reduce across your input.
The input is derived from the list of epics using a map
.
I use some simple type conversions to get the proper increments and output types.
(let [add-days (fn [d days]
(java.util.Date. (long (+ (.getTime d)
(* 1000 60 60 24 days)))))
initial {:x (java.util.Date.)
:y 42}
our-epics ["ARP-37" "ARP-22" "ARP-6"]]
(reductions (fn [tally epic-n]
{:x (add-days (:x tally) epic-n)
:y (long (- (:y tally) epic-n))})
initial
(map #(get epics %)
our-epics)))
({:x #inst "2014-02-18T22:31:17.027-00:00", :y 42}
{:x #inst "2014-02-26T22:31:17.027-00:00", :y 34}
{:x #inst "2014-03-11T22:31:17.027-00:00", :y 21}
{:x #inst "2014-04-01T22:31:17.027-00:00", :y 0})