{"id":13744684,"url":"https://github.com/kemsky/stream","last_synced_at":"2026-02-05T19:02:47.349Z","repository":{"id":81923921,"uuid":"43599613","full_name":"kemsky/stream","owner":"kemsky","description":"ActionScript collection library with modern functionality","archived":false,"fork":false,"pushed_at":"2016-02-20T15:35:22.000Z","size":503,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-15T16:41:15.880Z","etag":null,"topics":["actionscript","adobe-air","adobe-flash","adobe-flex","collections","functional-programming"],"latest_commit_sha":null,"homepage":"","language":"ActionScript","has_issues":true,"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/kemsky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-03T13:17:34.000Z","updated_at":"2018-09-19T07:31:18.000Z","dependencies_parsed_at":"2023-05-05T14:22:32.758Z","dependency_job_id":null,"html_url":"https://github.com/kemsky/stream","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemsky%2Fstream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemsky%2Fstream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemsky%2Fstream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemsky%2Fstream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kemsky","download_url":"https://codeload.github.com/kemsky/stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253183257,"owners_count":21867390,"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":["actionscript","adobe-air","adobe-flash","adobe-flex","collections","functional-programming"],"created_at":"2024-08-03T05:01:14.074Z","updated_at":"2026-02-05T19:02:47.341Z","avatar_url":"https://github.com/kemsky.png","language":"ActionScript","readme":"# stream [![Build Status](https://api.travis-ci.org/kemsky/stream.svg)](https://travis-ci.org/kemsky/stream)\n###ActionScript collection library - Stream\n\nBasically stream is an array wrapper that adds many useful methods and properties (`filter`, `iterate`, `map`, `fold`, `flatMap`, `first`, `second` ...  , `last`, `empty` etc.).\n\nInspired by Javascript and Ruby arrays, Scala collections. \n\nComplete documentation, unit tests with 100% code coverage, Travis CI integration (automatic testing, asdoc and coverage report generation).\n\nSee [latest release](https://github.com/kemsky/stream/releases/latest).\n\n## Creating Stream\n```as3\nvar s:Stream = $(1, 2, 3);\nvar s:Stream = $([1, 2, 3]);\nvar s:Stream = $(new ArrayCollection([1, 2, 3]));\nvar s:Stream = $(new ArrayList([1, 2, 3]));\nvar s:Stream = $(new Stream([1, 2, 3]));\n\nvar s:Stream = Stream.from([1, 2, 3]);\nvar s:Stream = Stream.of(1, 2, 3);\n\n//All expressions are equivalent to:\nvar s:Stream = new Stream([1, 2, 3])\n\n//Create from iterable object\nvar obj:Object = {name1: \"first\", name2: \"second\"};\nvar s:Stream = Stream.from(obj);\ntrace(s);\n//prints Stream{Stream{\"name1\", \"first\"}, Stream{\"name2\", \"second\"}}\n\n//create stream from object property names or property values\nvar s:Stream = Stream.fromKeys(obj);\ntrace(s);\n//prints Stream{\"name1\", \"name2\"}\n\nvar s:Stream = Stream.fromValues(obj);\ntrace(s);\n//prints Stream{\"first\", \"second\"}\n\n//create from XMLList or XML\nvar s:Stream = $(\u003croot\u003e\u003citem\u003e1\u003c/item\u003e\u003citem\u003e2\u003c/item\u003e\u003c/root\u003e);\nvar s:Stream = Stream.from(\u003croot\u003e\u003citem\u003e1\u003c/item\u003e\u003citem\u003e2\u003c/item\u003e\u003c/root\u003e);\ntrace(s);\n//prints Stream{\u003citem\u003e1\u003c/item\u003e, \u003citem\u003e2\u003c/item\u003e}\n```\n\n## Iteration and element access\nStream extends Proxy class and provides the same iteration capabilities as standard Array:\n```as3\nvar s:Stream = $(1, 2, 3);\nfor each (var item:* in s)\n{\n   trace(item);\n}\n\nfor (var i:int = 0; i \u003c s.length; i++)\n{\n   trace(s[i]);\n   trace(s.getItem(i));\n}\n//prints 1, 2, 3\n\n//iterator\nvar values:Iterator = s.iterator();\nwhile (values.hasNext)\n{\n   var n:Number = values.next();\n   //values.item;\n   //values.index;\n   //values.remove();\n   //values.end();\n}\n//or use standard for each loop\nfor each (var item:Number in values)\n{\n   //values.item;\n   //values.index;\n   //values.remove();\n   //values.end();\n}\n\n\n//set item at index 0\ns.setItem(5, 0);\ns[0] = 5;\ns.first = 5;\n//last item also has index -1, item before last -2 and etc. (Ruby-like)\ns[-3] = 5;\n\n//remove item from Stream\ndelete s[0];\ns.removeItem(0);\n```\n*Stream is about 10x slower when accessed by index (`[index]`) and it seems to be Proxy overhead.\nIf you need better performance (3x slower than Array) use methods to access Stream items: `getItem(index)` and `setItem(value, index)`.*\n\n## Convert Stream to any collection\n```as3\nvar s:Stream = Stream.of(1, 2, 3);\n\nvar collection:ArrayCollection = s.collection();\nvar array:Array = s.array();\nvar vector:Vector.\u003cObject\u003e = s.vector();\nvar list:ArrayList = s.list();\n```\n\n## Array-like methods\nStream has all methods(every, forEach, map, some, slice, splice, push, pop etc.) that standard Array has:\n```as3\nvar s:Stream = $(1, 2, 3);\ns.forEach(function(item:Number):void\n{\n    trace(item);\n});\n//or\ns.forEach(function(item:Number, index:uint):void\n{\n    trace(item);\n});\n//or\ns.forEach(function(item:Number, index:uint, stream:Stream):void\n{\n    trace(item);\n});\n//prints 1, 2, 3\n```\n\n## foldLeft, foldRight methods\n\nJavascript Array has `reduce` method which is quite similar.\n```as3\nvar sum2:Number = $(0, 1, 2, 3, 4).foldRight(function (prev:Number, current:Number):Number\n{\n   return prev + current;\n}, 10);\ntrace(sum2);\n//prints 20\n```\n\n## flatMap, flatten\n```as3\nvar s:Stream = new Stream([1, 2, 3], $(4, 5, 6), new ArrayCollection([7, 8, 9]));\nvar mapped:Stream = s.flatMap(function(item:*):*\n{\n   //this is nop callback, used just for example\n   //you can use short form: s.flatten();\n   return item;\n});\ntrace(mapped);\n//prints 1, 2, 3, 4, 5, 6, 7, 8, 9\n```\n\n## Various filtering methods\n\n```as3\n//filter out null, NaN or undefined items\nvar s:Stream = Stream.of(null, NaN, undefined).compact();\ntrace(s, s.length);\n//prints Stream{}, 0\n\n\npublic class Item\n{\n  public var name:String;\n  public var price:Number;\n}\n\nvar item1:Item = new Item(\"1\", 1);\nvar item2:Item = new Item(\"2\", 2);\nvar s:Stream = $(item1, item2);\n\n// 1. using custom callback\nvar result:Stream = s.filter(function(item:Item):Boolean{\n   return item.price \u003e 1;\n});\n\n// 2. using provided global functions(can compare Boolean, Number, Date, XML, String types)\n//    supports nested properties i.e. member(\"prop.prop.prop\")\nvar result:Stream = s.filter(gt(member(\"price\"), 1));\n\n// 3. using Proxy magick and global functions\nvar result:Stream = s.price(gt(_, 1)); \n\n//all three provide identical results\n```\n\n## E4X descendant accessor operator `..`\nShort alternative to `map` method:\n```as3\nvar item1:Item = new Item(\"car\", 1);\nvar item2:Item = new Item(\"truck\", 2);\nvar s:Stream = $(item1, item2);\n\nvar prices:Stream = s..price;\n\ntrace(prices);\n//prints 1,2\n```\n\n## Many other handy methods and properties\nStream can be converted to Object, Dictionary or custom class (using `group` method).\n```as3\nvar item1:Item = new Item(\"1\", 1);\nvar item2:Item = new Item(\"2\", 2);\nvar s:Stream = $(item1, item2);\n\nvar d:Dictionary = s.dictionary(\"name\");\n\ntrace(d[\"1\"], item1);\n//prints first item\n\ntrace(s.second);\n//prints second item\n\ntrace(s.unique);\n//prints true\n\ntrace(s.contains(item1));\n//prints true\n\ntrace(s.count(function(item:Item):Boolean\n{\n   return item.price \u003e 1;\n}));\n//or\ntrace(s.count(gt(member(\"price\"), 1)));\n//prints 1\n```\n\nSee also: `group`,`partition`,`fill`,`find`,`findIndex`, `drop`, `zip`, `zipWithIndex`, `skip` etc.\n\n## Build\n\nYou can build library using **Intelij Idea** or **Apache Maven**.\n - Compile `mvn compile -Dtag.name=\u003c...\u003e`\n - Run tests `mvn test -DflashPlayer.command=\"\u003cpath to flash player projector\u003e\"`\n - Generate coverage report `mvn flexmojos:coverage-report -DflashPlayer.command=\"\u003cpath to flash player projector\u003e\"`\n - Generate documentation: `mvn flexmojos:asdoc` \n","funding_links":[],"categories":["Utilities"],"sub_categories":["Other Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkemsky%2Fstream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkemsky%2Fstream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkemsky%2Fstream/lists"}