在clojure中,如何从映射绑定? [英] In clojure, how does one bind from a map?

查看:109
本文介绍了在clojure中,如何从映射绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定地图:

 (def myMap {a1b2c3d 4e5f6})



我希望使用 let 将每个键绑定到每个值。 c>使用 myMap 解决方案

作为声明,字符串键的解构看起来像是最好的打赌:

 (let [{:strs [abcdef]} myMap] 
(println abcdef))
; => 1 2 3 4 5 6


Given the map:

(def myMap {"a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6})

I wish to use let to bind each key to each value. What is the most concise way to do this?

解决方案

with myMap as declared, destructuring of string keys seems like the best bet:

(let [{:strs [a b c d e f]} myMap] 
    (println a b c d e f))
;=> 1 2 3 4 5 6

这篇关于在clojure中,如何从映射绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆