JSPM

pull-map

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q20967F
  • License MIT

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

Package Exports

  • pull-map

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pull-map) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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][package] travis [downloads/month][package] [downloads][package] [license][package] support me follow [package]: https://npmjs.com/package/pull-map