pull-map

0.1.1 • Public • Published

pull-map

Create sync, async, or through maps in pull-streams

var map = require('pull-map')
 
pull(
  pull.values([1, 2, 3, 4, 5]),
 
  // Sync map
  map(num => num * 3),
 
  // Async map
  map((num, done) => {
    hash(num, done)
  }),
 
  pull.log()
)

The map function is like pull.map and pull.asyncMap combined, by sync or async depending if the done callback is provided. There is also map.through, which passes data on undefined.

Installation

$ npm install --save pull-map

Usage

map(fn)

A through stream that maps values with map(x => ...) or async map with map((x, cb) => ...). Async map's callback takes cb(err, data). One function for all your pull-stream mapping needs!

// A sync map
var foo = map(source => source.toLowerCase())
 
// An async map
var bar = map((source, done) => {
  fs.readFile(source, done)
})

map.through(fn)

The same sync/async functionality as map, except passes on data if it receives undefined. Useful when you only want to replace some of the data in the pipeline.

pull(
  pull.values([1, 2.5, 3, 4.5, 5])
  map.through(function (num) {
    if (num !== Math.floor(num)) return -num
  })
  pull.collect(function (err, nums) {
    console.log(nums)
    // => [1, -2.5, 3, -4.5, 5]
  })
)
### `map.sync(fn)` ### `map.async(fn)`

The sync and async map methods behind map.

pull(
  count(),
  map.sync(x => x * 3)
  map.async(function (x, done) {
    hash(x, done)
  }),
  pull.log()
)

License

MIT © Jamen Marz


version travis downloads/month downloads license support me follow

Package Sidebar

Install

npm i pull-map

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • npm