hypercore-reduce

1.0.0 • Public • Published

hypercore-reduce

Build Status

Reduce from an initial state as a function of a hypercore

Usage

var reduce = require('hypercore-reduce')

var initial = {}
// Feed is a hypercore instance
reduce(feed, reducer, initial, done)

function reducer (prevState, curState, next) {
  return next(null, Object.assign(prevState, curState))
}

function done (err, finalState) {
  if (err) throw err

  console.log(finalState)
}

API

var destroy = reduce(feed, [readOpts], reducer, initial, done)

Reduce a hypercore feed from an initial state initial, calling reducer(state, currentItem, callback), where callback(err, state) will update the state. When the feed is completely consumed, done(err, state) will be invoked with the final state. If an error occurs, done is also invoked. Optionally readOpts can be passed as argument to feed.createReadStream.

A destroy(err) function is returned, which can be used to destroy the underlying stream.

Install

npm install hypercore-reduce

License

ISC

Readme

Keywords

none

Package Sidebar

Install

npm i hypercore-reduce

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

7.17 kB

Total Files

6

Last publish

Collaborators

  • emilbayes