Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

streams-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streams-as-promised

Your streams are now promises in your favourite promise library.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

streams-as-promised

Your streams are now promises in your favourite promise library, so you no longer have to choose between using streams and functional programming. An instance of a stream in this sense is either the empty Stream (a promise of an empty Array) or a promise of both a dynamic value and Stream.

    Stream :: EmptyStream | Promise [Dynamic, Stream]

Intro

npm install streams-as-promised

then

var Stream = require('streams-as-promised')(Promise);

where ```Promise```` is your favourite promise library (bluebird is advised).

Examples

To create a stream from an array:

var stream = new Stream([0,1,2,3]);

To read from a node readable stream:

var stream = (new Stream()).read(readable);

To write to a node writable stream:

var sameStreamForChaining = stream.write(writable);

To apply a function fn to every value in a stream:

var mappedStream = stream.map(fn);

using the .then function will return a promise of an array, if you want to chain streams use

    Stream.prototype.next(Function onResolved, Function ifEmpty, [Function onRejected]) -> Stream

here

    onResolved(Dynamic x, Stream xs) -> Stream | [Dynamic, Stream]
    ifEmpty() -> Stream
    onRejected(Dynamic reason) -> Stream

e.g.

var streamOfTypes = stream.next(function(x, xs){
	return [typeof x, xs];
}, function(){
	return [];
});

Keywords

FAQs

Package last updated on 22 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc