meander

Zachary 2023-08-21T04:49:45.250029Z

I have a vector of maps in the following shape, with only the keys I care about: [{:data [{:id ?id :external_data {:image ?image :name ?name}} ...] } ...] I’m able to get it to produce the logical variables that I’m interested in on a single map in that vector, put that in a function and map over the whole vector. But I’m wondering if there’s a way to do that better in one transformational step. So that I get something like [{:id 1 :image "image1" :name "foo" }, {:id 2 :image "image2" :name "bar" }...] I’ve tried the ! bang memory variables with ..., but that seems to group all the memory vars together, and really I want them put into a particular shape. Hope it’s okay to ask this here! I definitely look forward to my journey into Meander... just starting with this library, but I do have many years writing Prolog--and a bit with other rewriting systems (Maude)--so excited to explore pattern matching in my other favorite language (Clojure, of course)!

telekid 2023-08-21T11:47:28.229059Z

Have you seen the combination of m/search and m/scan? From https://github.com/noprompt/meander/blob/epsilon/doc/understanding.md#search

(m/search [1 2 1 3 1 5]
  (m/scan 1 ?x) ?x)
;; => (2 3 5)

Zachary 2023-08-21T14:48:01.430859Z

Ah, yes... that is indeed doing the do! 👍

👍 1
telekid 2023-08-21T18:03:04.522819Z

Once you get comfortable with search with scan, it’s worth trying to solve your problem with search alone. search with scan is just a special case of search, and search by itself is quite a bit more powerful, so it’s nice to know how to use it.

👀 1
telekid 2023-08-21T18:03:25.675219Z

(And find is just search where you only care about the first result.)