StreamJS is a very small (4.1kb minified) library that provides the power of streams for your computational needs.
TweetStreamJS is small library that provides the power of streams for your computational needs.
Get the latest release from Github or via npm/bower.
npm install stream-js
bower install stream-js
Streams can be created using the constructor function or using the helper methods: from and fromArray.
var streamOf2 = new Stream(1, function () {
return new Stream(2, null);
});
var stream = Stream.create(1,2,3);
var streamFromArray = Stream.fromArray([1,2,3]);
var s = Stream.create(1,2,3);
var sum = s.reduce(function(a, b) {
return a + b;
});
console.log(sum);
//6
var evenNaturals = NaturalNumbers().filter(function(val) {
return val % 2 === 0;
});
var oddNaturals = NaturalNumbers.filter(function(val) {
return val % 2 === 1;
});
var first100EvenNums = evenNaturals.pick(100); var sum = first100EvenNums.sum(); console.log(sum); //10100
1. A detailed blog post with more examples is available here.
2. Open your console and play with it!