meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
wilkerlucio 2021-03-20T23:21:49.011400Z

hello, I have a case that I'm trying to figure if meander can solve, I have data that can come in the following formats:

; contains rental prices and sales price
{:pricingInfos [{:rentalInfo      {:period                  "MONTHLY",
                                   :warranties              [],
                                   :monthlyRentalTotalPrice "4520"},
                 :yearlyIptu      "278",
                 :price           "3690",
                 :businessType    "RENTAL",
                 :monthlyCondoFee "830"}
                {:yearlyIptu      "278",
                 :price           "990000",
                 :businessType    "SALE",
                 :monthlyCondoFee "830"}]}

; contains only sales price
{:pricingInfos [{:yearlyIptu      "278",
                 :price           "990000",
                 :businessType    "SALE",
                 :monthlyCondoFee "830"}]}
and I like to match on the sales price only, I tried:
(m/match {:pricingInfos [{:rentalInfo      {:period                  "MONTHLY",
                                            :warranties              [],
                                            :monthlyRentalTotalPrice "4520"},
                          :yearlyIptu      "278",
                          :price           "3690",
                          :businessType    "RENTAL",
                          :monthlyCondoFee "830"}
                         {:yearlyIptu      "278",
                          :price           "990000",
                          :businessType    "SALE",
                          :monthlyCondoFee "830"}]}
  {:pricingInfos [{:price        ?price
                   :businessType "SALE"}]}
  {:sales-price ?price})
but that triggers an error of non exhaustive pattern match, is there a way to do a match like this with meander? (that kinda "finds" the matching item from a list)

phronmophobic 2021-03-20T23:26:44.011800Z

I think m/find with m/scan will do what you want:

> (m/find {:pricingInfos [{:rentalInfo      {:period                  "MONTHLY",
                                           :warranties              [],
                                           :monthlyRentalTotalPrice "4520"},
                         :yearlyIptu      "278",
                         :price           "3690",
                         :businessType    "RENTAL",
                         :monthlyCondoFee "830"}
                        {:yearlyIptu      "278",
                         :price           "990000",
                         :businessType    "SALE",
                         :monthlyCondoFee "830"}]}
  {:pricingInfos (m/scan
                  {:price        ?price
                   :businessType "SALE"})}
  {:sales-price ?price})

;;{:sales-price "990000"}

wilkerlucio 2021-03-20T23:28:08.012100Z

work as a charm, thanks!

👍 1
phronmophobic 2021-03-20T23:28:43.012500Z

if you want to find multiple items, you can use m/search in place of m/find

wilkerlucio 2021-03-20T23:44:10.012700Z

cool, what if I like to optionally matching also the rental price (which sometimes may not be there), what is the way to go?

wilkerlucio 2021-03-20T23:44:37.012900Z

I was able to match here when both are available, but the same pattern returns nil in case I remove the rental data

phronmophobic 2021-03-20T23:53:59.013100Z

not sure I understand the question. do you have an example?