Closed
Description
I’m implementing list-ops as a library, and I've got some questions about the best way to proceed. Consider
source list_ops.sh
double() { echo $(( $1 * 2 ));}
list=( 1 2 3 4 )
list::map double list # or
list::map double "${list[@]}"
Should the array be passed by name, or should the elements be passed? For a map
function it doesn't really matter, but if the list function is something like intersection
it would make more sense to pass 2 array names.
Also, struggling with the best way to return a result array:
- the safest way is to force the user to pass an array name:
result=()
list::map double list result # in some order
printf "%s\n" "${result[@]}"
- the simpler method, command substitution, is subject to word splitting and globbing:
result=( $( list::map double list ) )
Metadata
Metadata
Assignees
Labels
No labels