Anonymous user
Apply a callback to an array: Difference between revisions
Move zsh to UNIX Shell; add more shells.
(add language: Retro) |
(Move zsh to UNIX Shell; add more shells.) |
||
Line 1,607:
( Add 1 to each item in the array )
a 5 [ 1 + ] map-array</lang>
{{works with|Bourne Shell}}
<lang bash>map() {
map_command=$1
shift
for i do "$map_command" "$i"; done
}
list=1:2:3
{{works with|ksh93}}
{{works with|pdksh}}
{{works with|zsh}}
<lang bash>map() {
typeset command=$1
shift
for i do "$command" "$i"; done
}
set -A ary 1 2 3
map print "${ary[@]}"</lang>
{{works with|zsh}}
a=(1 2 3)▼
map print $a</lang>
=={{header|Ursala}}==
Line 1,677 ⟶ 1,703:
If F takes 2 arguments, x and , then simply pass them to map. They will be passed to F when as it is applied to each element of A.
<lang vorpal>A.map(F, x, y)</lang>
▲=={{header|Zsh}}==
▲<lang zsh>map(){for i ($*[2,-1]) $1 $i}
▲a=(1 2 3)
▲map print $a</lang>
{{omit from|gnuplot}}
|