简体   繁体   English

如何通过收藏绑定?

[英]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: 我有此函数可创建颜色名称和相关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 正如Juan所提到的,解决方案是让combine-color-imgurl返回地图然后使用

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

to get the URL. 获取URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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