Fixing bug in foldr

This commit is contained in:
Sławomir Śledź 2017-08-23 01:03:01 +02:00
parent dcdbaf22de
commit 3cf325d4aa
2 changed files with 14 additions and 4 deletions

View file

@ -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'

View file

@ -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"
}