{"id":13744690,"url":"https://github.com/danschultz/as3-collections","last_synced_at":"2026-03-12T23:31:50.354Z","repository":{"id":1132062,"uuid":"1008505","full_name":"danschultz/as3-collections","owner":"danschultz","description":"An AS3 library of collection classes, including maps, lists, sets, and for..each iteration.","archived":false,"fork":false,"pushed_at":"2011-05-19T07:31:08.000Z","size":275,"stargazers_count":17,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-25T22:55:42.153Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"ActionScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danschultz.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-10-20T08:31:51.000Z","updated_at":"2017-07-12T14:10:28.000Z","dependencies_parsed_at":"2022-07-15T07:30:58.955Z","dependency_job_id":null,"html_url":"https://github.com/danschultz/as3-collections","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/danschultz/as3-collections","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultz%2Fas3-collections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultz%2Fas3-collections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultz%2Fas3-collections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultz%2Fas3-collections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danschultz","download_url":"https://codeload.github.com/danschultz/as3-collections/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultz%2Fas3-collections/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30449043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T21:31:01.033Z","status":"ssl_error","status_checked_at":"2026-03-12T21:30:43.161Z","response_time":114,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-08-03T05:01:14.187Z","updated_at":"2026-03-12T23:31:50.327Z","avatar_url":"https://github.com/danschultz.png","language":"ActionScript","funding_links":[],"categories":["Utilities"],"sub_categories":["Other Utilities"],"readme":"# Welcome to AS3-Collections - Version 1.2.0\nThis framework provides a simple and tested library for representing groups of objects \nin AS3 and Flex. It is licensed under MIT.\n\nAS3-Collections follows the guidelines of [semantic versioning](http://www.semver.org).\n\n## Types of Collections\nAs of now, this framework supports the more common types of collections. These include:\n\n* Maps\n\t* `HashMap` - Maps a key's hash to a value.\n\t* `ImmutableMap` - Wraps a map to make it unmodifiable.\n* Lists\n\t* `ArrayList` - A mutable list of elements.\n\t* `ImmutableList` - Wraps a list to make it unmodifiable.\n* Sets\n\t* `HashSet` - A collection that contain no duplicate elements, and doesn't preserve iteration order.\n\t* `ArraySet` - Similar to HashSet, but preserves the order of iteration for its elements.\n\t* `ImmutableSet` - Wraps a set to make it unmodifiable.\n\nMore performance tuned collections may be introduced in the future. These could include \n`TreeMap`s, `LinkedList`s, etc. However, the current set of collections, I feel, cover the vast \nmajority of use cases in Flex.\n\nQueues can be accomplished through `List` and its subclasses.\n\n### Immutable Collections\nEach generic type of collection has an unmodifiable class that can wrap it.\n\n**Example** Creating an immutable collection.\n\tvar map:HashMap = new HashMap({a:1, b:2, c:3, d:4, e:5});\n\treturn new ImmutableMap(map);\n\nThis approach limits the number of classes required to provide immutability to the framework. In\naddition, these wrappers will work out of the box for custom collections that are created by other\ndevelopers. This also allows clients to create and use a modifiable collection within a class. But,\nprovide immutable access to these collections via accessor methods.\n\n**Example** Using immutable and mutable collections within a class.\n\tclass Post\n\t{\n\t\tprivate var _comments:ArraySet = new ArraySet();\n\t\t\n\t\tpublic function Post()\n\t\t{\n\t\t\t\n\t\t}\n\t\t\n\t\tpublic function comment(text:String, commenter:User):void\n\t\t{\n\t\t\t_comments.add(new Comment(text, commenter));\n\t\t}\n\t\t\n\t\tpublic function get comments():ISet\n\t\t{\n\t\t\treturn new ImmutableSet(_comments);\n\t\t}\n\t}\n\n## Design Goals\n\n### Equality\nA primary goal when implementing these collections was giving clients better control on\nobject equality and hashing. In addition to an objects' identity (`===`), elements are \nchecked for the existance of an `equals()` method. If this method exists, it is used \nfor comparing the equality between two elements.\n\n**Example**\nTake the case where you have a `Person` object. How does equality in this library compare\nto equality in AS3/Flex?\n\n\t// a HashSet from as3-collections\n\tvar personSet:HashSet = new HashSet([new Person(1)]);\n\ttrace(personSet.contains(new Person(1))); // true\n\t\n\t// a Flex collection\n\tvar personCollection:ArrayCollection = new ArrayCollection([new Person(1)]);\n\ttrace(personCollection.contains(new Person(1))); // false\n\t\n\t// an AS3 array\n\tvar personArray:Array = [new Person(1)];\n\ttrace(personArray.indexOf(new Person(1)) != -1); // false\n\t\n\tclass Person\n\t{\n\t\tpublic var id:int;\n\t\t\n\t\tpublic function Person(id:int)\n\t\t{\n\t\t\tthis.id = id;\n\t\t}\n\t\t\n\t\tpublic function equals(p:Person):Boolean\n\t\t{\n\t\t\treturn p != null \u0026\u0026 id == p.id;\n\t\t}\n\t}\n\t\n### Hashing\nAn equally important goal was to give clients more control with object hashing. Keys that \nare inserted into a map are checked for the existence of a `hashCode()` method. If the method\nexists, its result turns into the hash for the key-value pair. In conjunction with `equals()`,\nthis functionality allows for colliding hashes.\n\n**Example** How maps compare to `Dictionary`'s.\n\n\t// Maps support colliding hashes and custom object equality.\n\tvar map:HashMap = new HashMap();\n\tmap.put(new Dog(1), \"Baron\");\n\tmap.put(new Cat(1), \"Jake\");\n\ttrace(map.grab(new Dog(1))); // Baron\n\t\n\t// Dictionaries only support object identity.\n\tvar dictionary:Dictionary = new Dictionary();\n\tdictionary[new Dog(1)] = \"Baron\";\n\tdictionary[new Cat(1)] = \"Jake\";\n\ttrace(dictionary[new Dog(1)]); // undefined\n\t\n\t// Dictionaries also can't support colliding hashes.\n\tdictionary[new Dog(1).hashCode()] = \"Baron\";\n\tdictionary[new Cat(1).hashCode()] = \"Jake\";\n\ttrace(dictionary[new Dog(1).hashCode()]); // Jake\n\t\n\tclass Animal\n\t{\n\t\tpublic var id:int;\n\t\t\n\t\tpublic function Animal(id:int)\n\t\t{\n\t\t\tthis.id = id;\n\t\t}\n\t\t\n\t\tpublic function hashCode():Object\n\t\t{\n\t\t\treturn id;\n\t\t}\n\t}\n\t\n\tclass Dog extends Animal\n\t{\n\t\tpublic function equals(dog:Dog):Boolean\n\t\t{\n\t\t\treturn dog != null \u0026\u0026 id == dog.id;\n\t\t}\n\t}\n\t\n\tclass Cat extends Animal\n\t{\n\t\tpublic function equals(cat:Cat):Boolean\n\t\t{\n\t\t\treturn cat != null \u0026\u0026 id == cat.id;\n\t\t}\n\t}\n\n### Syntax Sugar\nI wanted to make working with these collections simple and familiar. There are touches of \nsyntax sugar sprinkled throughout the API.\n\n#### Iteration\nAll collections support `for each..in` loops. Additionally, copies of the collection are \ncreated during iteration. This allows for safe removal of an element within a loop.\n\n**Example** Iterating a collection.\n\tvar list:ArrayList = new ArrayList([1, 2, 3, 4, 5]);\n\tfor each (var num:int in list) {\n\t\ttrace(num);\n\t}\n\n**Example** Safe removal of elements.\n\tvar set:ArraySet = new ArraySet([1, 2, 3, 4, 5]);\n\tfor each (var num:int in set) {\n\t\tif (num == 2) {\n\t\t\tlist.remove(2);\n\t\t} else {\n\t\t\ttrace(num);\n\t\t}\n\t}\n\t\n\t// traces:\n\t// 1\n\t// 3\n\t// 4\n\t// 5\n\n#### Smart\nWhen possible, collections try to interpret the type of data you pass to it.\n\n**Example** `Array`'s are interoperable with `Collection`'s.\n\tvar list:ArrayList = new ArrayList();\n\tlist.addAll([1, 2, 3, 4, 5]);\n\tlist.containsAll([1, 2, 3, 4, 5]); // true;\n\ttrace(list.difference([1, 2])); // 3, 4, 5\n\n#### Access Operators.\nAll lists support bracket (`[]`) access of their elements.\n\n**Example** Reading and writing elements to a list using brackets (`[]`).\n\tvar list:ArrayList = new ArrayList([1, 2, 3, 4, 5]);\n\tlist[0] = 5;\n\tlist[4] = 1;\n\ttrace(list[1]); // 2\n\n#### Externalization.\nAll collections support reading and writing to a `ByteArray`. This sets up the framework\nfor sending collections over the wire in AMF. Clients will need to map the collections \non the server.\n\n**Example** Reading and writing to a `ByteArray`.\n\tvar set:HashSet = new HashSet([1, 2, 3, 4, 5]);\n\tvar bytes:ByteArray = new ByteArray();\n\tbytes.writeObject(set);\n\t\n\tbytes.position = 0;\n\tvar newSet:HashSet = bytes.readObject();\n\ttrace(newSet); // 1, 2, 3, 4, 5\n\n### Easy Sub-Classing\nAn important design constraint was making these collections easy to sub-class for developers.\nAs such, each collection type has a small and specific set of methods that must be implemented.\nAll are well documented within the collection base classes (i.e. `Map`, `Collection`, `Set`, `List`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanschultz%2Fas3-collections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanschultz%2Fas3-collections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanschultz%2Fas3-collections/lists"}