noprompt / meander

Tools for transparent data transformation
MIT License
921 stars 55 forks source link

Can not use var in m/find m/scan? #147

Closed zhaoyul closed 3 years ago

zhaoyul commented 3 years ago

The following works great.

(m/find [{:name "Alice" :id 1} {:name "Bob" :id 2} {:name "Bob" :id 3}] (m/scan {:name "Bob" :as ?Bob }) ?Bob) ;; => {:name "Bob", :id 2}

But, after I define a variable bob, and pass it to the m/find expression, it evals to nil?

(def bob "Bob")

(m/find [{:name "Alice" :id 1} {:name "Bob" :id 2} {:name "Bob" :id 3}] (m/scan {:name bob :as ?Bob }) ?Bob) ;; => nil

Any ideas?

problem solved:

(m/find [{:name "Alice" :id 1} {:name "Bob" :id 2} {:name "Bob" :id 3}] (m/and (m/scan {:name ?bob :as ?Bob }) (m/let [?bob bob])) ?Bob)