specter 2025-11-10

What is the Specter idiom for "remove something at a path if there is something there, but if there is nothing there return the structure as is"? This does what I want

(setval
 [:a :b :c]
 NONE {:a {:b {:c :foo}}})
It returns {:a {:b {}}} but this doesn't
(setval
 [:a :b :c]
 NONE {})
It returns {:a {:b nil}

Looks good. Thanks!

(setval
 [(must :a) (must :b) (must :c)]
 NONE
 {:a {:b {:c :foo}}})
;; => {:a {:b {}}}

(setval [(must :a) (must :b) (must :c)] NONE {})
;; => {}

you can (must :a :b :c)

❤️ 1

Think I have a string-related edge-case, when using setval and nthpath

(setval [(s/srange 1 2)] ["there"] [1 2 3 4]) ;; => [1 "there" 3 4] ;-- unbracketed "there" results in a char-list
(setval [(s/nthpath 1)] "there" [1 2 3 4]) ;; => [1 "there" 3 4]

(setval [(s/srange 1 2)] "there" "1234");; => "1there34"
(setval [(s/nthpath 1)] "there" "1234") ;; => "1[\"there\"]34"
setvaling on an index of a string adds these brackets and quotes, where I'd expect something more similar to srange's result

nthpath doesn't work on strings currently

if it did, the code you tried should probably error

since an index of a string is an individual character

nthpath shouldn't be able to splice a new string in

Makes sense, this isn't mission critical for anything I'm working on, I was just being very lazy and trying to use specter to alter a busted character in my REPL :^) I know a number of specter functions/navigators are supposed to work with strings, is there an enumeration of what does/doesn't?

ahhh the cheat-sheet I appreciate it, I was just staring at the macro/nav lists ⭐