Higher-order functions: Difference between revisions
Content added Content deleted
Line 282: | Line 282: | ||
filtered(lstRange, isEven) |
filtered(lstRange, isEven) |
||
--> {0, 2, 4, 6, 8, 10}</lang> |
--> {0, 2, 4, 6, 8, 10}</lang> |
||
As a footnote on lifting 2nd class AppleScript handlers into 1st class script objects for use with higher order functions, the role of '''mReturn''' or '''mInject''' can be inlined in such functions as followed, if preferred: |
|||
<lang AppleScript>-- [a] -> (a -> b) -> [b] |
|||
on map(xs, f) |
|||
script mf |
|||
property call : f |
|||
end script |
|||
set lst to {} |
|||
set lng to length of xs |
|||
repeat with i from 1 to lng |
|||
set end of lst to mf's call(item i of xs, i, xs) |
|||
end repeat |
|||
return lst |
|||
end map</lang> |
|||
=={{header|ATS}}== |
=={{header|ATS}}== |