Fork me on GitHub
#rewrite-clj
<
2020-10-20
>
Noah Bogart14:10:54

thank you, i'm trying that out now

Noah Bogart15:10:19

that got me on the right path, thank you

Noah Bogart15:10:14

my next issue is trying to create a new map node and then insert values into it from the surrounding node

Noah Bogart15:10:12

i have maps that have a :choices key that is sometimes a list or vector, and I'd like to wrap it in a map. from :choices existing-list to something like :choices {:buttons existing-list}

Noah Bogart15:10:26

(n/map-node) seems to work to create the node, but then I can't use z/assoc to insert key value pairs

Noah Bogart15:10:53

throws an "rewrite_clj.node.seq.SeqNode cannot be cast to clojure.lang.IFn" error

Noah Bogart15:10:06

any suggestions?

borkdude18:10:43

@nbtheduke Sometimes I find it easier to just use the raw nodes instead of zippers, so I grab the :children and manually rewrite them and assoc them back in

Noah Bogart18:10:58

huh, okay. i'll see if i can figure out how to do that. thanks

borkdude18:10:18

@nbtheduke This is the primary approach when writing clj-kondo hooks: https://github.com/borkdude/clj-kondo/blob/master/doc/hooks.md

borkdude18:10:16

Thanks btw, I didn't know about z/assoc

Noah Bogart18:10:58

ha there isn't a lot of documentation, so i've just been poring over the generated docs and trying things out. my code looks wack, so this is all great info

borkdude18:10:57

@nbtheduke if it helps, here's also a lib I made for rewriting config files: https://github.com/borkdude/rewrite-edn

borkdude18:10:14

it's still pretty young and maybe incomplete

borkdude18:10:32

but it should make things easier than working directly with rewrite-clj if you only need to assoc or update-in etc

Noah Bogart18:10:55

nice! did you implement maintaining whitespace as well? your examples look like it

Noah Bogart18:10:57

that's very cool

borkdude18:10:07

yeah, it uses rewrite-clj under the hood