{"id":13624901,"url":"https://github.com/winterbe/streamjs","last_synced_at":"2025-04-16T01:32:51.858Z","repository":{"id":25170780,"uuid":"28593843","full_name":"winterbe/streamjs","owner":"winterbe","description":"Lazy Object Streaming Pipeline for JavaScript","archived":false,"fork":false,"pushed_at":"2017-08-19T13:58:34.000Z","size":385,"stargazers_count":859,"open_issues_count":0,"forks_count":66,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-04-05T03:07:50.773Z","etag":null,"topics":["javascript","stream","stream-pipeline","streaming-api"],"latest_commit_sha":null,"homepage":"http://winterbe.github.io/streamjs/","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winterbe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-29T13:54:45.000Z","updated_at":"2025-03-10T10:34:14.000Z","dependencies_parsed_at":"2022-08-06T03:15:35.088Z","dependency_job_id":null,"html_url":"https://github.com/winterbe/streamjs","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fstreamjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fstreamjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fstreamjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fstreamjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winterbe","download_url":"https://codeload.github.com/winterbe/streamjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249182473,"owners_count":21226072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","stream","stream-pipeline","streaming-api"],"created_at":"2024-08-01T21:01:47.842Z","updated_at":"2025-04-16T01:32:51.570Z","avatar_url":"https://github.com/winterbe.png","language":"JavaScript","readme":"Stream.js [![Travic CI](https://travis-ci.org/winterbe/streamjs.svg?branch=master)](https://travis-ci.org/winterbe/streamjs)\n========================\n\n**ATTENTION: Stream.js is no longer maintained in favor of it's successor library [Sequency](https://github.com/winterbe/sequency). If you already use Stream.js in your project I recommend switching to [Sequency](https://github.com/winterbe/sequency). But don't worry, Stream.js still works fine so no hurry. 😉**\n\n\u003e Lazy Object Streaming Pipeline for JavaScript - inspired by the [Java 8 Streams API](http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/)\n\n```js\nStream(people)\n   .filter({age: 23})\n   .flatMap(\"children\")\n   .map(\"firstName\")\n   .distinct()\n   .filter(/a.*/i)\n   .join(\", \");\n```\n\n\u003cp align=\"center\"\u003e\n   \u003ci\u003eFollow on \u003ca href=\"https://twitter.com/winterbe_\"\u003eTwitter\u003c/a\u003e for Updates\u003c/i\u003e\n\u003c/p\u003e\n\n# Getting started\n\nStream.js is a lightweight (**2.6 KB minified, gzipped**), intensely tested (**700+ assertions, 97% coverage**) functional programming library for operating upon collections of in-memory data. It requires EcmaScript 5+, has built-in support for [ES6 features](https://github.com/lukehoban/es6features) and works in all current browsers, [Node.js](http://nodejs.org/) and Java 8 [Nashorn](http://openjdk.java.net/projects/nashorn/).\n\nDownload the [latest release](https://github.com/winterbe/streamjs/releases) from GitHub or install Stream.js via [NPM](https://www.npmjs.com/package/streamjs) or [Bower](http://bower.io/):\n\n```bash\nnpm install streamjs\n\n# or\n\nbower install streamjs\n```\n\n\u003cp align=\"center\"\u003e\n   \u003ci\u003eRead the \u003ca href=\"https://github.com/winterbe/streamjs/blob/master/APIDOC.md\"\u003eAPIDOC\u003c/a\u003e\u003c/i\u003e\n\u003c/p\u003e\n\n# Examples\n\nBefore explaining how Stream.js works in detail, here's a few real world code samples.\n\nFilter and sort a collection of persons, then group everything by age.\n\n```js\nStream(people)\n   .filter({married: true, gender: 'male'})\n   .sorted(\"lastName\")\n   .groupBy(\"age\");\n```\n\nFilter and transform a collection of tweets to its text content, then limit the tweets to a maximum of 100 and partition the results into 10 tweets per page:\n\n```js\nStream(tweets)\n   .filter(function (tweet) {\n      return tweet.author !== me;\n   })\n   .map(\"text\")\n   .filter(/.*streamjs.*/i)\n   .limit(100)\n   .partitionBy(10);\n```\n\nCreate an array of 100 odd random numbers between 1 and 1000:\n\n```js\nStream\n   .generate(function() {\n      return Math.floor(Math.random() * 1000) + 1;\n   })\n   .filter(function (num) {\n      return num % 2 === 1;\n   })\n   .limit(100)\n   .toArray();\n```\n\nCreate an infinite iterator, generating an odd random number between 1 and 1000 on each call to `next()`:\n\n```js\nvar iterator = Stream\n   .generate(function() {\n      return Math.floor(Math.random() * 1000) + 1;\n   })\n   .filter(function (num) {\n      return num % 2 === 1;\n   })\n   .iterator();\n\niterator.next();\niterator.next();\n```\n\nCreate an array of 100 parent objects, each holding an array of 10 children:\n\n```js\nStream\n    .range(0, 100)\n    .map(function (num) {\n        return {\n            parentId: num,\n            type: 'parent',\n            children: []\n        };\n    })\n    .peek(function (parent) {\n        parent.children = Stream\n            .range(0, 10)\n            .map(function (num) {\n                return {\n                    childId: num,\n                    type: 'child',\n                    parent: parent\n                };\n            })\n            .toArray();\n    })\n    .toArray();\n```\n\n# How Streams work\n\nStream.js defines a single function `Stream` to create new streams from different input collections like _arrays_, _maps_ or _number ranges_:\n\n```js\nStream([1, 2, 3]);\nStream({a: 1, b: 2, c: 3});\nStream.of(1, 2, 3);\nStream.range(1, 4);\n```\n\nStreams are monadic types with a bunch of useful operations. Those functions can be chained one after another to make complex computations upon the input elements. Operations are either *intermediate* or *terminal*. Intermediate operations are lazy and return the stream itself to enable method chaining. Terminal operations return a single result (or nothing at all). Some terminal operations return a special monadic `Optional` type which is described later.\n\nStreams are not limited to finite data sources like collections. You can also create *infinite* streams of elements by utilizing generator or iterator functions.\n\n```js\nStream.generate(function() {\n   return 1337 * Math.random();\n);\n```\n\n```js\nStream.iterate(1, function (seed) {\n   return seed * 2;\n});\n```\n\n# Why Stream.js?\n\nWhat's so different between Stream.js and other functional libraries like Underscore.js?\n\nStream.js is built around a lazily evaluated operation pipeline. Instead of consecutively performing each operation on the whole input collection, objects are passed vertically and one by one upon the chain. Interim results will _not_ be stored in internal collections (except for some stateful operations like `sorted`). Instead objects are directly piped into the resulting object as specified by the terminal operation. This results in **minimized memory consumption** and internal state.\n\nStream operations are lazily evaluated to avoid examining all of the input data when it's not necessary. Streams always perform the minimal amount of operations to gain results. E.g. in a `filter - map - findFirst` stream you don't have to filter and map the whole data. Instead `map` and `findFirst` are executed just one time before returning the single result. This results in **increased performance** when operation upon large amounts of input elements.\n\n```js\nStream([1, 2, 3, 4])\n   .filter(function(num) {   // called twice\n      return num % 2 === 0;\n   })\n   .map(function(even) {     // called once\n      return \"even\" + even;\n   })\n   .findFirst();             // called once\n```\n\n# [API Documentation](https://github.com/winterbe/streamjs/blob/master/APIDOC.md)\n\nThe Stream.js API is described in detail [here](https://github.com/winterbe/streamjs/blob/master/APIDOC.md). For more information about Java 8 Streams I recommend reading the official [Javadoc](http://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html) and this [blog post](http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/).\n\nA type definition for using Stream.js with **Typescript** is available [here](https://github.com/borisyankov/DefinitelyTyped/tree/master/streamjs).\n\n# Contributing\n\nFound a bug or missing feature? Please open an [issue](https://github.com/winterbe/streamjs/issues)! Your feedback and help is highly appreciated. Please refer to the [contributing rules](https://github.com/winterbe/streamjs/blob/master/CONTRIBUTING.md) before sending a pull request. I would also love to hear your feedback via [Twitter](https://twitter.com/benontherun).\n\n# Copyright and license\n\nCreated and copyright (c) 2014-2016 by Benjamin Winterberg.\n\nStream.js may be freely distributed under the [MIT license](https://github.com/winterbe/streamjs/blob/master/LICENSE).\n","funding_links":[],"categories":["javascript","Libraries"],"sub_categories":["[Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinterbe%2Fstreamjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinterbe%2Fstreamjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinterbe%2Fstreamjs/lists"}