Fork me on GitHub
#specter
<
2016-08-26
>
sashton19:08:50

I’m trying to write a navigator that drops n items. Here’s what I’ve got:

(spm/defnav nav-drop [n]
  (select* [this structure next-fn]
           (let [ret (next-fn (drop n structure))
                 empt (empty structure)]
             (if (= ret sp/NONE)
               ret
               (into empt ret))))
  (transform* [this structure next-fn]
              (let [ret (next-fn (drop n structure))]
                (->> (concat (take n structure) ret)
                     (into (empty structure))))))
I found I had to check the return value of next-fn to check for NONE. Is that the right approach? My original attempt was done assuming I’d just get back an empty list, but that didn’t work.

nathanmarz20:08:41

@sashton the select* implementation should just be (next-fn (drop n structure))

nathanmarz20:08:37

you're on 0.12.0, right?

sashton20:08:00

that changes the data type to a list, though, right?

sashton20:08:13

even if my input is a vector?

sashton20:08:28

i was trying to preserve the collection type

nathanmarz20:08:58

the requirement of select* is to call next-fn on whatever subvalue should be passed to the next navigator

nathanmarz20:08:20

so you should put the logic to maintain type before you call next-fn

nathanmarz20:08:41

probably (next-fn (into (empty structure) (drop n structure)))

sashton20:08:50

ah, i’ll give that a try

nathanmarz20:08:37

you only need to deal with NONE when a navigator navigates to an indeterminate number of subvalues