https://github.com/jamen/pull-map
Create sync, async, or through maps in pull-streams
https://github.com/jamen/pull-map
Last synced: about 1 year ago
JSON representation
Create sync, async, or through maps in pull-streams
- Host: GitHub
- URL: https://github.com/jamen/pull-map
- Owner: jamen
- License: mit
- Created: 2017-02-07T21:32:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-07T22:27:38.000Z (over 9 years ago)
- Last Synced: 2025-03-23T11:31:37.250Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# pull-map
> Create sync, async, or through maps in pull-streams
```js
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`](#api_map) function is like [`pull.map`](https://github.com/pull-stream/pull-stream/blob/master/docs/throughs/map.md) and [`pull.asyncMap`](https://github.com/pull-stream/pull-stream/blob/master/docs/throughs/async-map.md) combined, by sync or async depending if the `done` callback is provided. There is also [`map.through`](#api_map_through), which passes data on `undefined`.
## Installation
```sh
$ npm install --save pull-map
```
## Usage
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!
```js
// A sync map
var foo = map(source => source.toLowerCase())
// An async map
var bar = map((source, done) => {
fs.readFile(source, done)
})
```
The same sync/async functionality as [`map`](#api_map), except passes on data if it receives `undefined`. Useful when you only want to replace some of the data in the pipeline.
```js
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`](#api_map).
```js
pull(
count(),
map.sync(x => x * 3)
map.async(function (x, done) {
hash(x, done)
}),
pull.log()
)
```
## License
MIT © [Jamen Marz](https://git.io/jamen)
---
[][package] [](https://travis-ci.org/pull-map/jamen) [][package] [][package] [][package] [](https://www.paypal.me/jamenmarz/5usd) [](https://github.com/jamen)
[package]: https://npmjs.com/package/pull-map