Apply a callback to an array: Difference between revisions
Content added Content deleted
Line 1,655: | Line 1,655: | ||
=={{header|Guish}}== |
=={{header|Guish}}== |
||
{{works with|guish|2. |
{{works with|guish|2.4.0}} |
||
<syntaxhighlight lang="guish"> |
<syntaxhighlight lang="guish"> |
||
# applies add2 (adds 2) to each element |
# applies add2 (adds 2) to each element |
||
map = { |
|||
r = |
|||
args = [tail(@*)] |
|||
for x @args { |
|||
r = [@r, call(@1, @x)] |
|||
} |
|||
return @r |
|||
} |
|||
add2 = { |
add2 = { |
||
return add(@1, 2) |
return add(@1, 2) |
||
} |
} |
||
l = {1, 2, 3, 4, 5, 6, 7} |
|||
dump each(add2, flat(@l)) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||