Right-compose functions with a z() utility function
MIT License
Chain function calls using a prototype function .z()
Very similar to zii but without polluting the Object prototype globally. This one allows you opt-in when should the z
utility be applied on the target object, allowing you to right-compose functions together. This is like the proposed pipeline operator |>
, but implemented in ES5.
z(value).z(first).z(second)
is the same as second(first(value))
npm install ziii
const z = require('ziii')
const result = z({age: 10}) // Call z() to wrap the input
.z(({age}) => ({age: age * 3})) // then .z() to continue the chain
.z(({age}) => ({age: age / 4}))
.z(({age}) => ({age: Math.ceil(age)}));
console.log(result) // {age: 8}
If you use TypeScript, then add this to your tsconfig.json
file:
{
...
"types": [
"node_modules/ziii/index.d.ts"
]
...
}
const z = require('ziii')
const {from} = require('rxjs')
const {map, filter} = require('rxjs/operators')
z(from([1, 2, 3, 4, 5]))
.z(filter(x => x % 2 === 1))
.z(map(x => x * 10))
.subscribe({
next: x => console.log(x)
})
const z = require('ziii')
const {fromIter, map, filter, forEach} = require('callbag-basics')
z(fromIter([1, 2, 3, 4, 5]))
.z(filter(x => x % 2 === 1))
.z(map(x => x * 10))
.z(forEach(console.log))