Add curry function
This commit is contained in:
parent
999f399480
commit
dcdbaf22de
2 changed files with 19 additions and 0 deletions
|
@ -47,3 +47,11 @@ echo -n ' abcdefg' | splitc | foldr lambda a b . 'echo $a$b' # gfedcba
|
|||
echo 'ls' | try λ cmd status ret . 'echo $cmd [$status]; echo $ret'
|
||||
|
||||
list {1..10} | filter lambda a . '[[ $(mod $a 2) -eq 0 ]] && ret true || ret false' | join , '[' ']' # [2,4,6,8,10]
|
||||
|
||||
function add() {
|
||||
expr $1 + $2
|
||||
}
|
||||
|
||||
|
||||
curry add3 add 3
|
||||
add3 9
|
11
src/fun.sh
11
src/fun.sh
|
@ -234,3 +234,14 @@ zip() {
|
|||
done
|
||||
}
|
||||
|
||||
function curry() {
|
||||
exportfun=$1; shift
|
||||
fun=$1; shift
|
||||
params=$*
|
||||
cmd=$"function $exportfun() {
|
||||
more_params=\$*;
|
||||
$fun $params \$more_params;
|
||||
}"
|
||||
eval $cmd
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue