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)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"}
work as a charm, thanks!
if you want to find multiple items, you can use m/search
in place of m/find
cool, what if I like to optionally matching also the rental price (which sometimes may not be there), what is the way to go?
I was able to match here when both are available, but the same pattern returns nil
in case I remove the rental data
not sure I understand the question. do you have an example?