How can I merge two sequences in clojure?

user1639206 picture user1639206 · Sep 30, 2012 · Viewed 37.4k times · Source

What is an idiomatic way to merge (or retrieve the union of) two lists (or sequences) in Clojure?

(merge l1 l2)

doesn't seem to be the solution:

a=> (merge '(1 2 3) '(2 3 4))
((2 3 4) 1 2 3)

Answer

Omri Bernstein picture Omri Bernstein · Sep 30, 2012

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)