specter

Latest version: 1.1.3
mmer 2020-05-18T15:45:42.040700Z

Hi a simple question but one that I have struggled to find an answer: I have a vector of maps and I want to return all the maps that contains a map entry that matches a particular value, for example all maps where :lang contains "EN".

spieden 2020-05-18T16:01:54.041500Z

@mmer I believe (spr/select [spr/ALL #(= "EN" (:lang %))] v-of-m) should do it

mmer 2020-05-18T16:02:51.042700Z

So obvious when you see it in front of you! Thanks @spieden

1
spieden 2020-05-18T16:05:01.045700Z

@nathanmarz I'm having an interesting issue combining transform and stay-then-continue . I'm replacing a map with a string via transform, and then specter seems to try to navigate the new value like it's still a map and I get class java.lang.String cannot be cast to class clojure.lang.Associative from do-keypath-transform . Does that sound familiar at all?

lvh 2020-05-19T20:27:48.052400Z

I'm confused: isn't that what stay then continue is supposed to do?

lvh 2020-05-19T20:28:24.052600Z

how do you want to transform the map if you've already stringified its contents? do you have a more complete toy example?

lvh 2020-05-19T20:28:33.052800Z

i'd assume you want postorder there

lvh 2020-05-19T20:28:46.053Z

ugh, sorry, I just read the backlog

spieden 2020-05-19T20:28:49.053200Z

Yeah that's what I ended up doing ⬇️

spieden 2020-05-19T20:28:52.053400Z

:)

mmer 2020-05-18T16:05:54.046400Z

There is another step to this: I have a vector of pairs of vectors. I want to add a value to the first vector based on a property in the second vector. Again a simple use case, and probably has a simple answer

spieden 2020-05-18T16:12:15.047100Z

@mmer You'd probably just handle all that inside your transform function

mmer 2020-05-18T16:13:39.048200Z

@spieden thanks, I was expecting to be able to pass the first vector to the transform function without having selected it based on the values in the second function.

spieden 2020-05-18T16:14:41.049Z

Ah hrm, well you can pass the whole tuple to the transform based on a value in the second

spieden 2020-05-18T16:14:54.049300Z

.. and then just transform the first vector in it and leave the other alone

mmer 2020-05-18T16:15:23.049800Z

That makes sense

spieden 2020-05-18T16:16:08.050800Z

(spr/transform [spr/ALL #(fn [[_ v2]] (pred? v2)] transform-v1 vs)

mmer 2020-05-18T16:18:27.051Z

Thanks

spieden 2020-05-18T16:41:10.051600Z

@nathanmarz Looks like switching to postorder via continue-then-stay did the trick!

spieden 2020-05-18T16:41:34.052Z

Many thanks for specter, as always -- not sure how I'd accomplish this work I'm doing without it

🙂 1