1 | # pull-stream/throughs/map
|
2 |
|
3 | > [].map for pull-streams
|
4 |
|
5 | ## Background
|
6 |
|
7 | Pull-streams are arrays of data in time rather than space.
|
8 |
|
9 | As with a [`[].map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map), we may want to map a function over a stream.
|
10 |
|
11 | ## Example
|
12 |
|
13 | ```js
|
14 | var map = require('pull-stream/throughs/map')
|
15 | ```
|
16 |
|
17 | ```js
|
18 | pull(
|
19 | values([0, 1, 2, 3]),
|
20 | map(function (x) {
|
21 | return x * x
|
22 | }),
|
23 | log()
|
24 | )
|
25 | // 0
|
26 | // 1
|
27 | // 4
|
28 | // 9
|
29 | ```
|
30 |
|
31 | ## Usage
|
32 |
|
33 | ### `map = require('pull-stream/throughs/map')`
|
34 |
|
35 | ### `map((data) => data)`
|
36 |
|
37 | `map(fn)` returns a through stream that calls the given `fn` for each chunk of incoming data and outputs the return value, in the same order as before.
|
38 |
|
39 | ## Install
|
40 |
|
41 | With [npm](https://npmjs.org/) installed, run
|
42 |
|
43 | ```
|
44 | $ npm install pull-stream
|
45 | ```
|
46 |
|
47 | ## See Also
|
48 |
|
49 | - [`brycebaril/through2-map`](https://github.com/brycebaril/through2-map)
|
50 | - [`Rx.Obsevable#map`](http://xgrommx.github.io/rx-book/content/observable/observable_instance_methods/map.html)
|
51 |
|
52 | ## License
|
53 |
|
54 | [MIT](https://tldrlegal.com/license/mit-license)
|