Apply a callback to an array: Difference between revisions
→{{header|AppleScript}}
Line 170:
For a more general implementation of '''map(list, function)'''
<lang applescript>-- [a] -> (a -> b) -> [b]
Line 192:
end repeat
end reduce
-- [a] -> (a -> Bool) -> [a]
on filter(xs, f)
set mf to mReturn(f)
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
if mf's call(v, i, xs) then
set end of lst to v
end if
end repeat
return lst
end filter
-- An ordinary AppleScript handler function
Line 210 ⟶ 225:
a + b
end sum
on isEven(n)
n mod 2 = 0
end isEven
set
{map(
{{Out}}
<pre>{{1, 4, 9, 16, 25, 36, 49, 64, 81, 100}, 55, {2, 4, 6, 8, 10}}</pre>
=={{header|AutoHotkey}}==
|