vacuumlabs-threading
v1.0.0
Published
Clojure-like threading macro for javascript
Downloads
2
Readme
Clojure-like 'thread-any' macro. Example:
const {thread, $$} = require('vacuumlabs-threading')
const x = thread('3',
parseInt,
[Math.max, 10, $$],
[Math.min, 20, $$])
assert.equal(x, 10)
Example with lodash:
const {thread, $$} = require('vacuumlabs-threading')
const data = [
{name: 'alice', score: 10},
{name: 'bob', score: 15},
{name: 'alice', score: 20},
{name: 'bob', score: 5},
]
const maxScore = (scores) => thread(
scores,
[lo.map, $$, (arg) => arg.score],
lo.max)
thread(
data,
[lo.groupBy, $$, 'name'],
[lo.mapValues, $$, maxScore],
[assert.deepEqual, $$, {alice: 20, bob: 15}])
})