Fixing bug in foldr
This commit is contained in:
parent
dcdbaf22de
commit
3cf325d4aa
2 changed files with 14 additions and 4 deletions
|
@ -54,4 +54,7 @@ function add() {
|
|||
|
||||
|
||||
curry add3 add 3
|
||||
add3 9
|
||||
add3 9
|
||||
|
||||
list a b c d | foldl lambda acc el . 'echo -n $acc-$el'
|
||||
list '' a b c d | foldr lambda acc el . 'if [[ ! -z $acc ]]; then echo -n $acc-$el; else echo -n $el; fi'
|
13
src/fun.sh
13
src/fun.sh
|
@ -85,11 +85,18 @@ foldl() {
|
|||
foldr() {
|
||||
local f="$@"
|
||||
local acc
|
||||
read acc
|
||||
|
||||
local zero
|
||||
read zero
|
||||
foldrr() {
|
||||
local elem
|
||||
read elem && acc=$(foldrr)
|
||||
|
||||
if read elem; then
|
||||
acc=$(foldrr)
|
||||
# [[ -z $acc ]] && echo $elem && return
|
||||
else
|
||||
echo $zero && return
|
||||
fi
|
||||
|
||||
acc="$({ echo $acc; echo $elem; } | $f )"
|
||||
echo "$acc"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue