Socket
Book a DemoInstallSign in
Socket

co-stream-map

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-stream-map

Map streams over streams

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

co-stream-map

Map a co stream over each chunk of another co stream.

build status

Example

Given a stream twice that emits strings and a stream chars the emits a string's chars, map chars over twice:

var map = require('co-stream-map');

// a stream that emits `str` twice

function twice(str){
  var i = 0;
  return function*(end){
    if (end) return;
    if (++i <3) return str;
  }
}

// a stream that emits `str` split up into chars

function chars(str){
  return function*(end){
    if (end) return;
    var first = str[0];
    str = str.slice(1);
    return first;
  }
}

var source = twice('bar');
var read = map(source, chars);

assert.equal('b', yield read());
assert.equal('a', yield read());
assert.equal('r', yield read());
assert.equal('b', yield read());
assert.equal('a', yield read());
assert.equal('r', yield read());
assert(!(yield read()));

API

map(stream, fn)

For every chunk stream emits, call fn with that chunk and read from the returned stream.

fn can be a Function or a GeneratorFunction.

Returns a readable stream.

Installation

$ npm install co-stream-map

License

MIT

FAQs

Package last updated on 19 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts