specter

Latest version: 1.1.3
sophiago 2018-05-23T00:03:21.000205Z

@nathanmarz ironically enough I needed to also write a version of the macro I was struggling with over the weekend that does just stack the lambda bindings at the top of the AST and replaces all instances of corresponding locals. I did this as before by calling setval from inside transform, which I get the sense is not an ideal way to use Specter, but don't fully understand how you rewrote it to use transformed inside the navigator.

nathanmarz 2018-05-23T02:24:19.000034Z

@sophiago it'll be easier to understand the navigators if you play with them on toy examples

sophiago 2018-05-23T02:35:05.000145Z

True. I tell myself I'm testing these on the simplest functions, but they're still macros doing fairly heavy source transformation. It seems clear the issue here is that I'm trying to apply transformed directly to a symbol, and only the first one that matches as well, rather than in example you gave where it's one level up from the node in a zipper.

sophiago 2018-05-23T02:38:44.000153Z

I suppose it's just the combination of learning what's essentially a whole DSL and wanting to use it immediately given how well it fits so many of my problems. For example, it would seem calling setval from inside transform as in the first example shouldn't cause a significant hit in perf, but I'd have to actually look at your macros or at least reread the wiki page about caching to make that judgment for sure. At least your docs are quite good πŸ™‚

huthayfa 2018-05-23T20:09:29.000109Z

hello guys, I am new to specter library. does anyone of you know which function is used to navigate the entire data structure tree and manipulate specific key

huthayfa 2018-05-23T20:11:20.000319Z

without providing a path to the key

tanzoniteblack 2018-05-23T20:11:27.000125Z

@huthayfa.ainqawi that's a little vague, can you give a minimal example of what you're working with and what you're trying to get to?

huthayfa 2018-05-23T20:12:15.000722Z

{ "key": "hsq.contentjsonsample.sampleKey", "value": { "links":[{"text":"anytext","url":"http://nowhere.com","precedence":"1"},{"text":"anytext","url":"http://nowhere.com","precedence":"2"}], "misc":[{"key":"keyName","value":"valuessssssss"},{"key":"keyName","value":"valuessssssss"}], "assets":[{"name":"facebooklogo","location":"/s3/cmb/facebooklogo.png","type":"image"},{"name":"mypdf","location":"/pdfLocation","type":"pdf"}], }, "language":"EN", "shortName": "my Sample Json key", "description": "my Sample Json key explain why this key" }

huthayfa 2018-05-23T20:12:46.000369Z

wherever there is assets key, I want to manipulate it

tanzoniteblack 2018-05-23T20:12:59.000773Z

I suspect you want https://github.com/nathanmarz/specter/wiki/List-of-Navigators#walker

tanzoniteblack 2018-05-23T20:14:44.000626Z

that said, walker is generally something I consider a "I have no idea what data's coming in, and I have no control over the format, and I'm ok with accidentally manipulating other keys that just happen to be called that", which is pretty heavy handed & crude

tanzoniteblack 2018-05-23T20:15:29.000410Z

so if you can narrow your path down to more (like, assets will always be inside a map stored at links, or something) it can help to prevent random bugs

schmee 2018-05-23T20:15:44.000616Z

you don’t need specter for this, you can use update from core: (update your-map :assets update-fn)

tanzoniteblack 2018-05-23T20:16:17.000314Z

@schmee update will only do it if you are directly manipulating a map, not if you need to find a map nested in a bigger data structure

huthayfa 2018-05-23T20:16:29.000276Z

@schmee does update do a nested map search

tanzoniteblack 2018-05-23T20:16:29.000356Z

(or multiple maps nested in a bigger structure)

schmee 2018-05-23T20:17:26.000316Z

well, you need to specify what this larger data structure looks like in order to get a sensible answer

huthayfa 2018-05-23T20:18:03.000551Z

I don't know where the assets happen in the structure, maybe at second or third level

huthayfa 2018-05-23T20:18:10.000623Z

it depends on the jsonSchema

nathanmarz 2018-05-23T20:24:59.000658Z

@huthayfa.ainqawi this code will run on every nested assets key with a walk that descends into all collections and map values (but not map keys):

(def NESTED-MAPS
  (recursive-path [] p
    (cond-path map? (continue-then-stay MAP-VALS p)
               coll? [ALL p]
               )))

(transform [NESTED-MAPS (must "assets")] my-transform-fn data)

πŸ‘ 1
πŸ’― 1
huthayfa 2018-05-23T20:28:09.000709Z

so the value returned from the NESTED-MAPS will replace the current value, right ?

huthayfa 2018-05-23T20:28:56.000678Z

@nathanmarz

huthayfa 2018-05-23T20:30:50.000307Z

oh sorry, I didn't see my-transform-fn

huthayfa 2018-05-23T20:31:05.000720Z

@nathanmarz thank you so much