specter

Latest version: 1.1.3
okocim 2019-01-24T20:13:05.043300Z

Question about updating a list of lists: If I have the following structure:

[[?x :a/b ?y]
 [?y :b/c ?z]
 ;; I WANT TO NAVIGATE HERE FOR INSERTION
 [?z :d/e ?a]]
where I want to insert:
[[?z :x/y "FOO"]
 [?z :x/k "BAR"]]
resulting in:
[[?x :a/b ?y]
 [?y :b/c ?z]
 [?z :x/y "FOO"]
 [?z :x/k "BAR"]
 [?z :d/e ?a]]
What is the path, and does that require transform? or replace-in? I’m trying to use
[S/ALL
 (S/pred= '[?y :b/c ?z])
 S/AFTER-ELEM]
for my path with a transform But that’s not working. I can’t assure the index of the insertion point will always be the same

schmee 2019-01-24T20:40:06.044Z

@okocim here’s a kludgy two-step solution:

user=> a
[[?x :a/b ?y] [?y :b/c ?z] [?z :d/e ?a]]

user=> b
[[?z :x/y "FOO"] [?z :x/k "BAR"]]

user=> (def i (select-one [INDEXED-VALS (selected? LAST (pred= '[?y :b/c ?z])) FIRST] a))
#'user/i

user=> (setval [(srange i (inc i)) END] b a)
[[?x :a/b ?y]
 [?y :b/c ?z]
 [?z :x/y "FOO"]
 [?z :x/k "BAR"]
 [?z :d/e ?a]]

okocim 2019-01-24T20:42:28.045Z

Thanks, I’ll take it for now. It is a bit fumbly, but I think I can cordon that off until I can come up with something better

schmee 2019-01-24T20:57:04.045400Z

If you find something cleaner post it here!

okocim 2019-01-24T20:58:08.046600Z

I will. I was headed down the path of doing the two steps (find the index and splice-in) when you posted this, so thank you. I will be happy to return the favor if I can.