union package:base

The union function returns the list union of the two lists. It is a special case of unionBy, which allows the programmer to supply their own equality test.

Examples

>>> "dog" `union` "cow"
"dogcw"
If equal elements are present in both lists, an element from the first list will be used. If the second list contains equal elements, only the first one will be retained:
>>> import Data.Semigroup(Arg(..))

>>> union [Arg () "dog"] [Arg () "cow"]
[Arg () "dog"]

>>> union [] [Arg () "dog", Arg () "cow"]
[Arg () "dog"]
However if the first list contains duplicates, so will the result:
>>> "coot" `union` "duck"
"cootduk"

>>> "duck" `union` "coot"
"duckot"
union is productive even if both arguments are infinite.
>>> [0, 2 ..] `union` [1, 3 ..]
[0,2,4,6,8,10,12..
The unionBy function is the non-overloaded version of union. Both arguments may be infinite.

Examples

>>> unionBy (>) [3, 4, 5] [1, 2, 3, 4, 5, 6]
[3,4,5,4,5,6]
>>> import Data.Semigroup (Arg(..))

>>> unionBy (/=) [Arg () "Saul"] [Arg () "Kim"]
[Arg () "Saul", Arg () "Kim"]