Fork me on GitHub
#specter
<
2016-09-18
>
fasiha04:09:47

I'm super-hesitant to ask this—I feel I ought to go thru the wikis listing the navigators and macros and other examples a couple more times (and as I just did). Can I navigate to "the space between the first and second element of a vec" and setval it, so that [:a :b :c] becomes [:a :NEW-VAL :b :c]?

karan04:09:44

try this:

(def my-nav (n/PosNavigator (fn [v] (nth v 1)) (fn [v afn]
                                                                 (let [val (nth v 1)]
                                                                   (assoc v 1 (afn val))))))

karan04:09:15

that will need to polymorphic on the second function (the transformer), but it’s the idea

karan04:09:01

oh never mind, that’s not what you asked 🙂. sorry!

karan04:09:02

(defnav POSONE []
                   (select* [this structure next-fn]
                            (next-fn []))
                   (transform* [this structure next-fn]
                               (let [new-val (next-fn [])]
                                 (vec (cons (first structure)
                                            (cons new-val (rest structure)))))))
@fasiha take two. similar caveats, but I think that’s the right direction.

nathanmarz11:09:26

@fasiha (setval (srange 1 1) [:NEW-VAL] [:a :b :c])