1.0.0 • Published 6 years ago

flat-map v1.0.0

Weekly downloads
1,769
License
MIT
Repository
github
Last release
6 years ago

#flat-map Build Status

A flat map implementation for node streams

##Installation npm install flat-map

##Usage

When the callback data is already flat passes it maps it normally:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray([1, 2, 3, 4, 5])
    .pipe(flatMap(function(data, callback) { callback(null, data.split(/\s/); }));
  // [1, 2, 3, 4, 5]    

When the callback data is an array it flattens and maps it accordingly:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray('one two', 'three', 'four five')
    .pipe(flatMap(function(data, callback) { callback(null, data.split(/\s/); });
  // ['one', 'two', 'three', 'four', 'five']    

When the callback data is a stream it flattens and maps it accordingly:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray('one two', 'three', 'four five')
    .pipe(flatMap(function(data, callback) { callback(null, es.readArray(data.split(/\s+/))) });
  // ['one', 'two', 'three', 'four', 'five']    

When the callback data is a promise it flattens and maps it accordingly:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray('one two', 'three', 'four five')
      .pipe(flatMap(function(data, callback) {
        callback(null, new Promise(function(resolve) { resolve(data); }))
      }));
  // ['one', 'two', 'three', 'four', 'five']
1.0.0

6 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.3

8 years ago

0.0.2

9 years ago

0.0.1

9 years ago