Awesome
hyperreduce
Distributed reduce on top of hypercore.
Usage
const hypercore = require('hypercore')
const memdb = require('memdb')
const reduce = require('./')
const core = hypercore(memdb())
const inp = core.createFeed()
const head = reduce(inp, memdb({ valueEncoding: 'json' }), reducer)
head(function (err, last) {
if (err) throw err
console.log('head:', last || 'no data')
})
function reducer (last, data, next) {
last = last || 0
console.log('last:', last)
next(null, last + data.length)
}
inp.append('hello planet')
inp.append('hello planet')
inp.append('hello planet')
Why
We believe ops doesn't need to be complicated. If hypercore
is distributed
streams, hyperreduce
is a distributed reducer for streams. We needed this to
to turn our feed of server errors into a single meaningful value.
API
getLasthyperReduce(inputFeed, db, reducer(last, data, next), done?)
Create a new reduce function that reads data from an input hypercore
feed to
and applies the reducer
function.
getLast(cb(err, last))
Get the last value from hyperreduce
.
Installation
$ npm install hyperreduce
See Also
- https://github.com/mafintosh/hypercore
- https://github.com/mafintosh/hyperpipe
- https://github.com/mafintosh/hypername
- https://github.com/mafintosh/hyperfilter
- https://github.com/yoshuawuyts/hypertail