Skip to content

Instantly share code, notes, and snippets.

@alebianco
Created November 21, 2012 16:13
Show Gist options
  • Save alebianco/4125736 to your computer and use it in GitHub Desktop.
Save alebianco/4125736 to your computer and use it in GitHub Desktop.
High order functions for arrays
/*
Author:
Daniel Gasienica
daniel@gasienica.ch
http://gasi.ch/
Originally published on
http://gasi.ch/blog/functional-actionscript-part-3/
Released under the
Creative Commons Attribution-Share Alike License
http://creativecommons.org/licenses/by-sa/3.0/
*/
package
{
/*
a beautiful example of a higher order function that takes a function
as argument and then constructs and returns a new function:
wrapper to make a function's signature conform to that of
a valid callback which looks like this, e.g. for the filter function
function callback(item:*, index:int, array:Array):Boolean;
http://livedocs.adobe.com/flex/3/langref/Array.html#filter()
*/
public function wrap( f : Function ) : Function
{
return(
function( x : *, index : int, array : Array ) : *
{
return f( x )
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment