AS#Enumerable

AS#Enumerable is a port of the Ruby Enumerable API for Actionscript 2.0. It provides the following enumerable methods for use in your flash applications:

It's provided as a subclass of the native Array object, but if you want all native Arrays to inherit the enumerable interface (a la Prototype) just add:

Array.prototype = new Enumerable();
to your Flash application. Some basic sample uses of Enumerable:

var enum = [];
enum.push(0.2);
enum.push(0.3);
enum.each(function(item,index) {
  trace(item + ':' + index);
});
(Using each for basic iteration).
var enum = [];
enum.push({value:'foo'});
enum.push({value:'bar'});
enum.push({value:'camp'});		
var item = enum.find(function(item,index) {
  return item.value == 'bar';
});
(Using find to fetch an object from a collection).
var enum = [];
enum.push('foo');
enum.push('bar');
enum.push('camp');	
trace(Math.floor(enum.inject(0,function(strlen,string) {
	return strlen + string.length;
})/enum.size()));
(Using inject and size to fetch the average string length in a collection of strings).

Go ahead and grab the source code, which will find its permanent home at /code, should you want to check back.

See the prototype enumerable API doc for further documentation, as the usage examples are identical in Actionscript 2.0. Thanks to Sam Stephenson of Prototype for the JS port.

→ More articles in Development, Software
Post a comment (0)

another thought

Arthur Russell - Another Thought (Keeping Up)

→ More articles in Media, Music
Post a comment (0)

#last.fm

[7:02pm] alex: Haskell users are all pretty nuts.
[7:02pm] johan: when the revolution comes they're first up against the wall
[7:02pm] alex: johan: Actually, they won't.
[7:02pm] alex: Haskell does not guarantee execution order.

→ More articles in Development, Software
Post a comment (0)

tropisms (part II)

Tropisms (Part II)

The second release in our series of Tropisms is now available as a high quality download. This one contains the next three Tropisms. Download it here.

→ More articles in Media, Music
Post a comment (0)

takashi homma







Above: Spread from 'Tokyo and my Daughter'. Below: Images from 'Tokyo Suburbia'


Takashi Homma is a japanese photographer. I really like 'Tokyo And My Daughter' and 'Tokyo Suburbia'. He's about to publish a volume which aggregates a selection of his work on Tokyo to date.

→ More articles in Design, Graphic, Media
Post a comment (0)