Apply a callback to an array: Difference between revisions
no edit summary
(Go solution) |
No edit summary |
||
Line 487:
Collect return values:
<lang factor>{ 1 2 3 4 } [ sq ] map</lang>
=={{header|Fantom}}==
In Fantom, functions can be passed to a collection iterator, such as 'each'. 'map' is used similarly, and the results are collected into a list.
<lang fantom>
class Main
{
public static Void main ()
{
[1,2,3,4,5].each |Int i| { echo (i) }
Int[] result := [1,2,3,4,5].map |Int i->Int| { return i * i }
echo (result)
}
}
</lang>
Output:
<pre>
1
2
3
4
5
[1, 4, 9, 16, 25]
</pre>
=={{header|Forth}}==
|