collections.immutable: Immutable collection classes for AS3
- There are no immutable collections in Flash or Flex.
- Immutable collections are fairly easy to create using standard AS3 and the magical Proxy class.
Lets take a step back and consider what I mean by an immutable collection. To demonstrate this, consider an arbitrary class Wibble:
class Wibble { public var wobble:Boolean = true; }
If we have an array of Wibble objects:
var array:Array = [new Wibble(), new Wibble(), new Wibble()]
we are free to manipulate that array as we wish:
array[1].wobble = false; array[0] = 0; array = null; array = [];
The last three actions change the array. The first one changes the state of one of the values of the array. This distinction is important, for if Array were immutable collection, only the first action would be valid. The values of an immutable collection cannot be changed, but the state of those values can be.
With that in mind, I have created a small suite of immutable collection classes:
| HashMap | An immutable version of the Dictionary class |
| OrderedList | An immutable version of the Array class |
| Tuple | A variation on OrderedList, designed for handling situations where functions need to return a set of loosely connected values |
| TypedHashMap | Variation on HashMap, which allows the type of the map’s values to be specified |
| TypedOrderedList | Variation on OrderedList, which allows the type of the elements of the list to be specified |
The API documentation is available online here. Don’t forget you can use “Doc? AIR” to create an offline version if that suits you better.
The SWC library and source can be downloaded here.
Tutorial posts on each of the classes will appear here soon.
TweetShare This Post...
3 comments so far, click here to read them or add another
3 Comments so far
Leave a reply


Can you use these with data binding?
@Rudiger,
Why would you ant to use data binding with these classes. Data binding is used to bind a component to a changeably piece of data. These collection classes are immutable, ie they do not change. So binding to them would have no effect.
I’m not sure why everyone is calling their dictionary wrappers a “HashMap” when they don’t use any hash and are still just IdentityMaps. It’s missleading. So far I’ve only seen ONE real AS3 hashmap, out of 10+.