Created
October 12, 2011 10:25
-
-
Save galak-fyyar/1280852 to your computer and use it in GitHub Desktop.
Implementing support of curry operation in Flex
This file contains hidden or 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
public class ChallengeLoader extends EventDispatcher { | |
public function loadWordSound( wordSoundUrl:String, onSuccess:Function, | |
onError:Function ):void { | |
var loadingProcessData:LoadingProcessData = new LoadingProcessData( onSuccess, | |
onError ); | |
var loadingEventProcessor:Function = FunctionUtils.curry( | |
onCompleteResourceLoad, loadingProcessData ); | |
var wordSound:Sound = new Sound(); | |
wordSound.addEventListener( Event.COMPLETE, loadingEventProcessor ); | |
wordSound.addEventListener( IOErrorEvent.IO_ERROR, loadingEventProcessor ); | |
var soundRequest:URLRequest = new URLRequest( wordSoundUrl ); | |
wordSound.load( soundRequest ); | |
} | |
private function onCompleteResourceLoad( loadingProcessData:LoadingProcessData, event:Event ) { | |
//process resource loading complete event | |
} | |
} |
This file contains hidden or 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
public class FunctionUtils { | |
public function FunctionUtils() { | |
throw new IllegalOperationError( "FunctionUtils should be used only as static utility" ); | |
} | |
public static function curry( func:Function, ... args:Array ):*{ | |
var arity:int = func.length; | |
var currying:Function = function( func:Function, arity:int, args:Array ):* | |
{ | |
return function( ... moreArgs:Array ):* { | |
if ( moreArgs.length + args.length < arity ) { | |
return currying( func, arity, args.concat( moreArgs ) ); | |
} | |
return func.apply( this, args.concat( moreArgs ) ); | |
} | |
}; | |
return currying( func, arity, args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment