Apply a callback to an array: Difference between revisions

added PostScript
(added PostScript)
Line 1,096:
 
If one wants to create a new array consisting of transformed values then procedure mapdata may be more convenient.
 
=={{header|PostScript}}==
The <code>forall</code> operator applies a procedure to each element of an array, a packed array or a string.
<lang postscript>[1 2 3 4 5] { dup mul = } forall</lang>
In this case the respective square numbers for the elements are printed.
 
To create a new array from the results above code can simply be wrapped in <code>[]</code>:
<lang postscript>[ [1 2 3 4 5] { dup mul } forall ]</lang>
 
=={{header|PowerShell}}==
Anonymous user