Fork me on GitHub
#specter
<
2019-08-22
>
Petrus Theron09:08:17

Can Specter emit reductions over a lensed collection? E.g. (something-specter [ALL :amount (reducer +)] [{:amount 10.0M} {:amount 20.0M} ...]) => [{:amount 10.0M} {:amount 30.0M} ...]

Petrus Theron09:08:04

E.g. w/o Specter:

(reductions
    (fn [[latest acc] [when amount]]
      [when (+ acc amount)])
    [0 0.0M]
    (zipmap (range 10) (range 10)))
=> ([0 0.0M] [0 0.0M] [7 7.0M] [1 8.0M] [4 12.0M] [6 18.0M] [3 21.0M] [2 23.0M] [9 32.0M] [5 37.0M] [8 45.0M])

lxsli11:08:04

@petrus Could traversed be what you're after?

Petrus Theron12:08:32

Thanks @alee traversed looks like it might work 🙂 (select-any (traversed ALL +) [1 2 3 4])

👍 4
lxsli11:08:45

Alternatively you might get mileage out of collect

lxsli11:08:07

Not an expert myself so no promises

Petrus Theron12:08:32

Thanks @alee traversed looks like it might work 🙂 (select-any (traversed ALL +) [1 2 3 4])

👍 4