简体   繁体   中英

How to bind through collection?

How do I match values through a list? In my case I have a list of colors -

["Black", "Lavender", "Brazen", "Army", "Birch"] 

I have this function that creates a collection of the color name and a related URL:

    (combine-color-imgurl get-product-images)
=>
[("Black"
  "example.com/WWbNhro1n3YfmQTx1q5Piv1j8lZzse6M-25_2a353315-9965-457f-83f8-32af89f3b067.jpeg")
 ("Lavender"
  "example.com/trWCTNYNOfiA8EBX9HZcxVB1Hg8pVtr9-25_403cbe3e-9894-4ad6-9f69-dedcfd7ef77b.jpeg")
 ("Brazen"
  "example.com/COYrBHEsiOgdeOfxsQGcw8XXynsVdpxy-25_af0a9ff9-b988-467e-9b39-c4ae572420e8.jpeg")
 ("Army"
  "example.com/YWKhJXFM0dKhJuRXphCXD4TWstnZRRJm-25_b3a2e43c-3c8c-4abc-83d2-d00d9b3ed594.jpeg")
 ("Birch"
  "example.com/IRsHVjavdFsybvmpT6xjnpKqMtjyjeoZ-25_6321e4ef-5bed-463f-990a-1857151b8a11.jpeg")]

I'm not exactly sure how to get only the URL related to the color.

So the function would be something like

(defn get-url [color]
  (some-operation (combine-color-imgurl get-product-images)))

=> URL 

As mentioned by Juan, the solution was to have combine-color-imgurl return a map then use

(get (into {} (combine-color-imgurl get-product-images)) color)

to get the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM