-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions arise while implementing list-ops exercise as library implementation #375
Comments
For testing, this is what I’ve got in the test script (pending this discussion): @test "map non-empty list" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash -c '
source list_ops.sh
list=(1 3 5 7)
incr () { echo $(( $1 + 1 )); }
#result=( $(list::map incr "${list[@]}") )
result=( $(list::map incr list) )
echo "${result[*]}"
'
[[ $status -eq 0 ]]
[[ $output == "2 4 6 8" ]]
} |
Relates to #373 |
Just tried another take in the test file:
The test failed due to the list::map function not existing in the child shell created by This way of writing the tests forces the library to Is that something a shell library should do? |
bash sucks at this sort of thing. Consider using known list names. listA listB result. The function is responsible to read from those lists and write to that list. The only real alternative is to pass variable names all over and use indirection. |
I’m implementing list-ops as a library, and I've got some questions about the best way to proceed. Consider
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 likeintersection
it would make more sense to pass 2 array names.Also, struggling with the best way to return a result array:
The text was updated successfully, but these errors were encountered: