Skip to content

Function: mergeSet() ​

mergeSet<T, U>(s1, s2): Set<T | U>

Merge two sets into a new one (their union): the items of the first, then the items of the second not already in it (compared as by Set: objects by reference). Neither set is modified.

Type Parameters ​

T ​

T = any

U ​

U = any

Parameters ​

s1 ​

Set<T>

The first items.

s2 ​

Set<U>

The items added after them.

Returns ​

Set<T | U>

A new set of the items of both.

Example ​

typescript
import {mergeSet} from 'lakutata/utils'

console.log([...mergeSet(new Set([1, 2]), new Set([2, 3]))])
//[1, 2, 3]

Released under the MIT License.