This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-14
Channels
- # announcements (2)
- # babashka (27)
- # beginners (20)
- # biff (1)
- # cljs-dev (2)
- # clojars (19)
- # clojure (50)
- # clojure-austin (10)
- # clojure-australia (8)
- # clojure-europe (23)
- # clojure-losangeles (1)
- # clojure-nl (1)
- # clojure-spec (7)
- # clojured (7)
- # clojurescript (19)
- # cursive (4)
- # datalevin (9)
- # datomic (15)
- # emacs (7)
- # fulcro (25)
- # gratitude (2)
- # helix (1)
- # holy-lambda (2)
- # hyperfiddle (14)
- # introduce-yourself (1)
- # jobs (5)
- # joyride (2)
- # juxt (3)
- # kaocha (9)
- # leiningen (14)
- # meander (9)
- # minecraft (34)
- # nbb (18)
- # off-topic (15)
- # polylith (12)
- # re-frame (4)
- # remote-jobs (1)
- # shadow-cljs (79)
- # vim (57)
Hello all! I’m pretty new to meander and I’m stuck trying to do the following (contrived example in thread):
Given an input of the form
(def input {:result {:brands-list {:items [{:url ""
:image ""
:id "52845"}]}
:products-list
[{:name "Product A"
:brand-id "1173500"
:price "33.00"}
{:name "Product B"
:brand-id "52845"
:price "20.65"}]}})
I’d like to get the product info like follows:
({:product-name "Product B",
:brand-id "52845",
:brand-url "",
:product-price "20.65"}
{:product-name "Product A",
:brand-id "1173500",
:brand-url nil,
:product-price "33.00"})
The tricky thing I can’t get to work is to get a “brand”’s :url
if the product’s :brand-id
matches one of the :id
s in :brands-list
but leave it blank otherwise.
Trying with
(defn products
[input]
(m/search input
{:result {:brands-list {:items (m/scan {:url ?brand-url
:id ?brand-id})}
:products-list (m/scan {:name ?product-name
:brand-id ?brand-id
:price ?product-price})}}
{:product-name ?product-name
:brand-id ?brand-id
:brand-url ?brand-url
:product-price ?product-price}))
I’m only able to get the product with a matching brand-id
(products input) => ({:product-name "Product B",
:brand-id "52845",
:brand-url "",
:product-price "20.65"})
https://github.com/noprompt/meander/issues/137 might help you. Sorry if that's not much help; it's late and I'm logging off.
thank you, this was helpful indeed! It is working with a combination of m/or
and m/let
(defn products
[input]
(m/search input
{:result {:products-list (m/scan {:name ?product-name
:brand-id ?brand-id
:price ?product-price})
:brands-list {:items (m/or (m/scan {:url ?brand-url
:id ?brand-id})
(m/let [?brand-url nil]
(m/not (m/scan {:id ?brand-id}))))}}}
{:product-name ?product-name
:brand-id ?brand-id
:brand-url ?brand-url
:product-price ?product-price}))