Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 24, 2025. It is now read-only.
/ weldy Public archive

A sort of pipe operator (|>) implementation for Node.js

License

Notifications You must be signed in to change notification settings

stearm/weldy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

weldy

JavaScript Style Guide Build Status

NPM

A sort of pipe operator (|> ) implementation for Node.js based on co.

weldy takes a value and an array with the following structure [ [fn_1, ...args], [fn_2, ...args], ... ,[fn_n, ...args] ], processes each element invoking fn, using as first argument the output of the previous one (if it returns any value) and the ...args. It returns a promise. The first argument of the first function can be passed as the first weldy param.

Examples

Simple arithmetical operations:

weldy(5, [ // first argument for sqrt function
 [ square ],
 [ sum, 3, 4, 5 ],
 [ sub, 4 ],
 [ console.log ] // 33
])

CRUD operations on mongodb:

function insert () {
 return db.collection('document').insertMany([
 { value: 'object1' },
 { value: 'object2' },
 { value: 'object3' }
 ])
}
function retrieve (value) {
 return db.collection('document').find({ value }).limit(1).next().then(object => object.value)
}
function update (value, newValue) {
 console.log(`Update collection: ${value} -> ${newValue}`)
 return db.collection('document').updateOne({ value }, { $set: { value: newValue } })
}
function isOk (object) {
 console.log(`Update ok: ${object.result.ok}`)
}
insert()
weldy('object1', [
 [ retrieve ],
 [ update, 'object0' ],
 [ isOk ]
])

Usage with node-fetch:

weldy('http://github.com', [
 [ fetch ],
 [ res => res.text() ],
 [ console.log ]
])

API

weldy(value, [[ [fn_1, ...args], [fn_2, ...args], ... ,[fn_n, ...args]] ]).then( val => )

where value is the first argument of the first function (// TODO: to improve).

License

MIT

About

A sort of pipe operator (|>) implementation for Node.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /