Did you know?
You are viewing an old version of this entry, click here to see latest version.
General
using and callback
The callback statement allows currying, thus enabling the use of multiple argument functions in places where single argument functions are expected, e.g.
var l:List<Float> = Lambda.map([1, 2, 3], callback(Math.pow, 2));The signature of Math.pow is "Float -> Float -> Float", which is not compatible with Lambda.map requiring a "Float -> Float" function here. However, with the callback statement the signature might be rewritten as "2 -> Float -> Float", i.e. a function with 2 as first argument that takes a Float and returns a Float. This is compatible with Lambda.map, which now calls Math.pow(2,1), Math.pow(2,2) and Math.pow(2,3).
The using statement also applies the callback mechanism:
using Math; var l:List<Float> = Lambda.map([1, 2, 3], 2.pow);The 2.pow is translated to exactly the above callback example. Finally, true functional beauty is achieved by another using statement:
using Math; using Lambda; var l:List<Float> = [1, 2, 3].map(2.pow);
Flash
flash.Memory to ByteArray
The contents of the memory modified through the flash.Memory API can easily be passed to functions expecting a ByteArray:
bitmapData.setPixels(bitmapData.rect, flash.system.ApplicationDomain.currentDomain.domainMemory);
Containers
Arrays are slow, use them only if you need indexed access to your elements. Lists aren't any better because their implementation is based on Arrays. If you don't need indexed access, consider using haxe.FastList.
version #8348, modified 2010-03-24 10:25:17 by Simn