0.1.2 • Published 4 years ago

@uniono/core v0.1.2

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

@uniono/core

Library contains one class - Union. This class is intended to manipulate any structure or object.

Union

Constructor

Creates new Union instance

ArgumentTypeDefaultDescription
isAtomfunctionFunction 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

ArgumentTypeDefaultDescription
unionanyUnion
mapFnfunctionMap 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

ArgumentTypeDefaultDescription
unionanyUnion
fnfunction
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 
// false

union.flat

Executes a provided function once for each union atom

ArgumentTypeDefaultDescription
unionanyUnion
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 ]