0.1.4 • Published 4 months ago

@fightingdreamer/set-union v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

set-union

Description

Missing union operation for Set or any Iterable.

Second implementation can do union operation between any number of iterables.

Install

bun add @fightingdreamer/set-union

Usage

import {union} from '@fightingdreamer/set-union'

const a = new Set([1,2,3])
const b = [3,4,5][Symbol.iterator]()
const result = union(a, b)
const expect = [1,2,3,4,5]
for (const value of expect) {
  console.assert(result.has(value))
}
import {unionMany} from '@fightingdreamer/set-union'

const sets = [
  [1,2,3][Symbol.iterator](),
  [3,4,5][Symbol.iterator](),
  [5,6,7][Symbol.iterator]()
][Symbol.iterator]()
const result = unionMany(sets)
const expect = [1,2,3,4,5,6,7]
for (const value of expect) {
  console.assert(result.has(value))
}

Usage (node / commonjs)

const {union} = require('@fightingdreamer/set-union')

const a = new Set([1,2,3])
const b = [3,4,5][Symbol.iterator]()
const result = union(a, b)
const expect = [1,2,3,4,5]
for (const value of expect) {
  assert(result.has(value))
}
const {unionMany} = require('@fightingdreamer/set-union')

const sets = [
  [1,2,3][Symbol.iterator](),
  [3,4,5][Symbol.iterator](),
  [5,6,7][Symbol.iterator]()
][Symbol.iterator]()
const result = unionMany(sets)
const expect = [1,2,3,4,5,6,7]
for (const value of expect) {
  assert(result.has(value))
}

Functions

function union<T>(a: Iterable<T>, b: Iterable<T>): Set<T>

Will apply union operation between Set and Iterable.

function unionMany<T>(sets: Iterable<Iterable<T>>): Set<T>

Will apply union operation between any number of Iterables.

0.1.4

4 months ago

0.1.2

5 months ago

0.1.3

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago