meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
grounded_sage 2020-01-23T11:29:13.053Z

I’m trying to match on some data and a bit confused as to how to approach it. The structure looks like this

{:key-1 [{:name "name" 
          :amount "amount" 
          {:sub-key-1 [{:name "name" 
                        :amount "amount"}
          ..(keeps repeating)..]}

grounded_sage 2020-01-23T11:29:36.053400Z

This is part of a larger structure which is using m/match.

grounded_sage 2020-01-23T11:30:58.054500Z

Currently I am telling Meander.

{:key-1 [{:name !name 
          :amount !amount} ...]}

grounded_sage 2020-01-23T11:31:42.055400Z

But this returns [!name …] and [!amount …] as separate lists.

grounded_sage 2020-01-23T12:43:03.055800Z

My best strategy was to just pass this into another function that performs a search

jimmy 2020-01-23T14:40:53.056700Z

What do you want to do with that data? What output are you looking for?

grounded_sage 2020-01-23T15:43:52.059Z

@jimmy I was trying to extract data from a vector of maps. Keeping the data of each map associated with one another.

grounded_sage 2020-01-23T15:45:37.060600Z

I ended up achieving the desired result by calling another function that performed a

(m/search param 
  (m/scan {...}))

grounded_sage 2020-01-23T15:46:46.061800Z

This is called on the logic variable (which I bound the entire vector structure to) inside the action of my top level m/match

jimmy 2020-01-23T15:50:19.063100Z

If you share your full code, we could talk about other ways you could accomplish the same thing. If you can't I understand

grounded_sage 2020-01-23T15:51:34.063700Z

I’ll try that later. Will have to remove the sensitive information from it.

jimmy 2020-01-23T16:01:45.064700Z

Even just giving an example of "this is my input and the output should be _" will help. But I'm glad you got something working :slightly_smiling_face:

timothypratley 2020-01-23T18:28:29.067500Z

“aligned memory variables” is a common question; if the arrays are strongly aligned you can just substitute, if they are ragged you can use ..!n to ensure the correct numbers are gathered, and you can also use a defsyntax or with sub pattern… more concrete examples for the cookbook would be useful so as you run into use cases it would be really helpful to share them in some anonymous cut down form.

grounded_sage 2020-01-23T19:52:47.069Z

@jimmy this is a Gist of a cut down version of what I have. https://gist.github.com/groundedSAGE/9dc0dd20113e29109dacdc08ba5dd66a I’m interested if there is a way to avoid the sales-category-transform function.

grounded_sage 2020-01-23T19:57:40.070400Z

@timothypratley I’m sure there is a way to do what I am wanting to do as Meander seems to cover a lot of ground. I’m very new to it though. Only looked at it last night and used it at work today.

jimmy 2020-01-23T20:35:25.071100Z

(m/rewrite data
  {:Data
   {:EventId ?event-id
    :Event ?event-name
    :Sales {:Overall {:TicketCount ?sales-ticket-count
                      :Amount ?sales-amount}
            :ByCategory [{:Name !names
                          :TicketCount !ticket-counts
                          :Amount !amounts} ...]}}}

  {:event {:id ?event-id
           :name ?event-name}
   :sales {:overall {:ticket-count ?sales-ticket-count
                     :amount ?sales-amount}
           :by-category [{:name !names
                          :ticket-count !ticket-counts
                          :amount !amounts} ...]}})
Here's how you can do that same thing using rewrite.

jimmy 2020-01-23T20:35:40.071300Z

@grounded_sage ^

jimmy 2020-01-23T20:39:56.072700Z

With rewrite, the right hand side is what is called a substitution. So you can do things like ... and get the memory variables to work how you want.

grounded_sage 2020-01-23T22:16:59.073500Z

That did it! @jimmy. Though I’m unsure which is the better choice as I know very little about this rewrite thing.

grounded_sage 2020-01-23T22:17:22.074300Z

I do think it is good having a full representation of input/output data instead of breaking it into other functions.

jimmy 2020-01-23T22:17:49.075100Z

Rewrite is match. But on the right hand side you can use substitute. Rewrite is definitely the better option here.

grounded_sage 2020-01-23T22:18:31.076100Z

Cool. Well thank you for the help 🙂

grounded_sage 2020-01-23T22:19:30.076500Z

Will be using this heavily at work so I’ll be around here a bit 😉

🙂 1