Distributed reduce on top of hypercore.
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')
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.
Create a new reduce function that reads data from an input hypercore
feed to
and applies the reducer
function.
Get the last value from hyperreduce
.
$ npm install hyperreduce