@uniono/core
v0.1.2
Published
Library to manipulate any unions
Downloads
7
Readme
@uniono/core
Library contains one class - Union. This class is intended to manipulate any structure or object.
Union
Constructor
Creates new Union instance
| Argument | Type | Default | Description | |-----------|-----------|----------|---------------------------------------------------------| | isAtom | function | | Function is a predicate to test each part of the union |
const arrayUnion = new Union((a) => Array.isArray(a))union.map
Creates new union with mapped atoms
| Argument | Type | Default | Description | |-----------|-----------|----------|---------------| | union | any | | Union | | mapFn | function | | Map function |
const booleanUnion = new Union((a) => typeof a === 'boolean')
console.log(booleanUnion.map({ a: true, b: 'true' }, (x) => !x)) // { a: false, b: 'true' }union.forEach
Executes a provided function once for each union atom
| Argument | Type | Default | Description | |-----------|-----------|----------|---------------| | union | any | | Union | | fn | function | | |
const booleanUnion = new Union((a) => typeof a === 'boolean')
booleanUnion.forEach(
{ a: true, b: false, n: 42, c: [ true, false ] },
(item) => console.log(item)
)
// true
// false
// true
// falseunion.flat
Executes a provided function once for each union atom
| Argument | Type | Default | Description | |-----------|-----------|----------|---------------| | union | any | | Union |
const booleanUnion = new Union((a) => typeof a === 'boolean')
console.log(booleanUnion.flat({ a: true, b: false, n: 42, c: [ true, false ] }))
// [ true, false, true, false ]