Created
August 19, 2013 12:32
-
-
Save knjname/6268642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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