Add curry function

This commit is contained in:
Sławomir Śledź 2017-08-22 09:37:44 +02:00
parent 999f399480
commit dcdbaf22de
2 changed files with 19 additions and 0 deletions

View file

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

View file

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