actionscript 3 - When would it make sense to pass a function to a function? -
OK, so it is possible to pass the function to another function.
This is clearly very powerful, but another important question is, when it is wise to do this, because whenever you call any other function, there are performance overheads ?
A function that takes the function as its argument is called higher sequence function is called
function (f, g) {return function (x) {return f (p) (return function) g (x)) ; }; } Function map (f, xs) {var ys = []; (Var i = 0; i & lt; xs.length; ++ i) ys.push (f (x [i])) for; Return ys; }
With that, you can change an array with two functions in one line:
var a = ["one", "two" , " three "]; Var b = Map (composition (touppercase, reverse), A); // B. Now ["EoO", "OWT", "EERHT"]
Comments
Post a Comment