Fork me on GitHub
#specter
<
2020-05-18
>
mmer15:05:42

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".

spieden16:05:54

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

mmer16:05:51

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

1
spieden16:05:01

@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?

lvh20:05:48

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

lvh20:05:24

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

lvh20:05:33

i'd assume you want postorder there

lvh20:05:46

ugh, sorry, I just read the backlog

spieden20:05:49

Yeah that's what I ended up doing ⬇️

mmer16:05:54

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

spieden16:05:15

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

mmer16:05:39

@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.

spieden16:05:41

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

spieden16:05:54

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

mmer16:05:23

That makes sense

spieden16:05:08

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

spieden16:05:10

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

spieden16:05:34

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

🙂 1