Skip to content

Instantly share code, notes, and snippets.

@knjname
Created August 19, 2013 12:32
Show Gist options
  • Select an option

  • Save knjname/6268642 to your computer and use it in GitHub Desktop.

Select an option

Save knjname/6268642 to your computer and use it in GitHub Desktop.
#!/bin/bash
foldl(){
local func="$1"
local prev="$2"
while read cur ; do
prev="$(eval $func "$prev" "$cur")"
done
echo $prev
}
add(){
echo $(( $1 + $2 ))
}
sum(){
foldl add 0
}
# bash => 55
# zsh => 55
seq 0 10 | sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment