Skip to content

Latest commit

 

History

History
72 lines (59 loc) · 2.31 KB

README.md

File metadata and controls

72 lines (59 loc) · 2.31 KB

hyperreduce stability

npm version build status downloads js-standard-style

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

License

MIT