Anonymous user
Apply a callback to an array: Difference between revisions
→{{header|Smalltalk}}
m (→{{header|Phix}}: comment -> use new requires() builtin) |
|||
Line 2,872:
=={{header|Smalltalk}}==
<lang smalltalk>#( 1 2.0 'three') do: [:each | each displayNl].</lang>
You can tell symbols how to react to the <tt>value:</tt> message, and then write ²:
<lang smalltalk>#( 1 2.0 'three') do: #displayNl.</lang>
2) actually most dialects already have it, and it is trivial to add, if it does not.
There is a huge number of additional enumeration messages implemented in Collection, from which Array inherits. Eg.:
<lang smalltalk>#( 1 2 3 4 5 ) collect: [:n | n * n].</lang>
|