如何在clojure中合并两个序列? [英] How can I merge two sequences in clojure?
本文介绍了如何在clojure中合并两个序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Clojure中合并(或检索两个列表(或序列)的联合)的惯用方式是什么?
What is an idiomatic way to merge (or retrieve the union of) two lists (or sequences) in Clojure?
(merge l1 l2)
似乎不是解决方案:
a=> (merge '(1 2 3) '(2 3 4))
((2 3 4) 1 2 3)
推荐答案
我认为andih的解决方案非常好。这里是一个替代方法,因为嘿为什么不。它使用 concat
和 distinct
:
I think andih's solution works great. Here is an alternate way because hey why not. It uses concat
and distinct
:
user> (distinct (concat '(1 2 3) '(2 3 4)))
=> (1 2 3 4)
这篇关于如何在clojure中合并两个序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文