Apply a callback to an array: Difference between revisions

m (Unicon/Icon consistency 2)
(→‎{{header|Ruby}}: ++ sather)
Line 1,022:
To create a new array of each value squared
<lang ruby>[1,2,3,4,5].map{ |i| i**2 }</lang>
 
=={{header|Sather}}==
<lang sather>class MAIN is
do_something(i:INT):INT is
return i * i;
end;
 
main is
a:ARRAY{INT} := |1, 2, 3, 4, 5|;
-- we use an anonymous closure to apply our do_something "callback"
a.map(bind(do_something(_)));
loop #OUT + a.elt! + "\n"; end;
end;
end;</lang>
 
=={{header|Scala}}==