如何将地图转换为序列? [英] How to convert map to a sequence?

查看:168
本文介绍了如何将地图转换为序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题解释如何将地图,序列等转换为各种序列和集合,但不说如何将地图转换为交替的键和值的序列。这里有一种方法:

Answers to this question explain how to convert maps, sequences, etc. to various sequences and collections, but do not say how to convert a map to a sequence of alternating keys and values. Here is one way:

(apply concat {:a 1 :b 2})
=> (:b 2 :a 1)

一些人可能天真地认为会产生相同的结果,不要,包括传递映射到 vec 向量 seq 序列 into [] into c>和 flatten

Some alternatives that one might naively think would produce the same result, don't, including passing the map to vec, vector, seq, sequence, into [], into (), and flatten. (Sometimes it's easier to try it than to think it through.)

有比 apply concat 更简单的东西吗?

Is there anything simpler than apply concat?

推荐答案

您也可以执行

(mapcat identity {:a 1 :b 2})

(mapcat seq {:a 1 :b 2})

这篇关于如何将地图转换为序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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