Fork me on GitHub
#specter
<
2018-09-26
>
Logan Powell15:09:45

👋 new guy here. I hope my question is simple: I'm looking for a way to map a function to a specific set of indices within a collection. For example:

(transform [ALL MAP-VALS [1 3 5]] inc [0 1 2 3 4 5 6])
;; wishful thinking => [0 2 2 4 4 6 6]
is such a thing straight-forward in specter?

drowsy16:09:27

@loganpowell something like (transform [INDEXED-VALS (selected? FIRST #{1 3 5}) LAST] inc [0 1 2 3 4 5 6]) works. Not sure if it's the best solution though.

Logan Powell17:09:41

@drowsy Thank you thank you

Logan Powell17:09:04

works like a charm!

schmee17:09:18

@loganpowell shorter and faster version:

user=> (transform (multi-path 1 3 5) inc [0 1 2 3 4 5 6])
[0 2 2 4 4 6 6]