Clojure:半平化嵌套序列 [英] Clojure: Semi-Flattening a nested Sequence
本文介绍了Clojure:半平化嵌套序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含向量嵌入列表的列表,如下所示:
I have a list with embedded lists of vectors, which looks like:
(([1 2])([3 4] [5 6])([7 8]))
我知道是不理想的。我想把它变成([1 2] [3 4] [5 6] [7 8])
。
Which I know is not ideal to work with. I'd like to flatten this to ([1 2] [3 4] [5 6] [7 8])
.
flatten不工作:它给我(1 2 3 4 5 6 7 8)
。
flatten doesn't work: it gives me (1 2 3 4 5 6 7 8)
.
我该如何做?我想我需要基于每个列表项目的内容创建一个新的列表,而不是项目,这是我从文档中找不到如何做。
How do I do this? I figure I need to create a new list based on the contents of each list item, not the items, and it's this part I can't find out how to do from the docs.
推荐答案
如果你只想将它展平一级,你可以使用 concat
If you only want to flatten it one level you can use concat
(apply concat '(([1 2]) ([3 4] [5 6]) ([7 8])))
=> ([1 2] [3 4] [5 6] [7 8])
这篇关于Clojure:半平化嵌套序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文