Created
November 21, 2012 16:13
-
-
Save alebianco/4125736 to your computer and use it in GitHub Desktop.
High order functions for arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author: | |
Daniel Gasienica | |
[email protected] | |
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