# union

## definition

The union method takes a Set as parameter and will merge its elements with the elements from the current Set.

```scala
def union(that: GenSet[A]): This
```

## demo

```scala
scala> val donuts1: Set[String] = Set("Plain Donut", "Strawberry Donut", "Glazed Donut")
donuts1: Set[String] = Set(Plain Donut, Strawberry Donut, Glazed Donut)

scala> val donuts2: Set[String] = Set("Plain Donut", "Chocolate Donut", "Vanilla Donut")
donuts2: Set[String] = Set(Plain Donut, Chocolate Donut, Vanilla Donut)

scala> donuts1 union donuts2
res9: scala.collection.immutable.Set[String] = Set(Vanilla Donut, Plain Donut, Chocolate Donut, Strawberry Donut, Glazed Donut)

scala> donuts2 union donuts1
res10: scala.collection.immutable.Set[String] = Set(Vanilla Donut, Plain Donut, Chocolate Donut, Strawberry Donut, Glazed Donut)

scala> donuts2 ++ donuts1
res11: scala.collection.immutable.Set[String] = Set(Vanilla Donut, Plain Donut, Chocolate Donut, Strawberry Donut, Glazed Donut)

scala> donuts1 ++ donuts2
res12: scala.collection.immutable.Set[String] = Set(Vanilla Donut, Plain Donut, Chocolate Donut, Strawberry Donut, Glazed Donut)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.selinux.tech/scala/function-operation/u/union.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
