Fork me on GitHub
#specter
<
2017-01-05
>
schmee07:01:16

how can I transform every nth element of a collection?

schmee07:01:19

I’ve tried various combinations of map-indexed but then I’m back to the ‘reconstruct the right type’ problem

schmee07:01:52

if I had a version of collected? that also gave you the current element, I guess something like this would work:

(sr/transform [(sr/collect sr/ALL) sr/ALL (sr/collected-with-current? [collected current] (= 0 (mod (.indexOf collected current) n)))] f (range 10))

nathanmarz07:01:26

@schmee you would either need zippers for that or a custom navigator

nathanmarz07:01:36

zippers are integrated with specter in com.rpl.specter.zipper

nathanmarz07:01:44

something like ALL-INDEXED which navigates to pair of [index value] should do the trick

schmee08:01:04

I’ll give the custom navigator a shot later today, thanks!