Minor fix + add some examples.
This commit is contained in:
parent
3cf325d4aa
commit
00d9c3916c
2 changed files with 65 additions and 4 deletions
|
@ -58,3 +58,63 @@ 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'
|
||||
|
||||
seq 1 4 | foldl lambda acc el . 'echo $(($acc + $el))'
|
||||
|
||||
#1 - 2 - 3 - 4
|
||||
seq 1 4 | foldl lambda acc el . 'echo $(($acc - $el))'
|
||||
#1 - 4 - 3 - 2
|
||||
seq 1 4 | foldr lambda acc el . 'echo $(($acc - $el))'
|
||||
|
||||
#1 + (1 + 1) * 2 + (4 + 1) * 3 + (15 + 1) * 4 = 64
|
||||
|
||||
seq 1 4 | foldl lambda acc el . 'echo $(mul $(($acc + 1)) $el)'
|
||||
|
||||
#1 + (1 + 1) * 4 + (8 + 1) * 3 + (27 + 1) * 2 = 56
|
||||
seq 1 4 | foldr lambda acc el . 'echo $(mul $(($acc + 1)) $el)'
|
||||
|
||||
tup a 1
|
||||
tupl $(tup a 1)
|
||||
tupr $(tup a 1)
|
||||
tup a 1 | tupl
|
||||
tup a 1 | tupr
|
||||
|
||||
seq 1 10 | buff lambda a b . 'echo $(($a + $b))'
|
||||
echo 'XX'
|
||||
seq 1 10 | buff lambda a b c d e . 'echo $(($a + $b + $c + $d + $e))'
|
||||
|
||||
list a b c d e f | zip $(seq 1 10)
|
||||
|
||||
echo
|
||||
list a b c d e f | zip $(seq 1 10) | last | tupr
|
||||
|
||||
arg='[key1=value1,key2=value2,key3=value3]'
|
||||
get() {
|
||||
local pidx=$1
|
||||
local idx=$2
|
||||
local arg=$3
|
||||
echo $arg | tr -d '[]' | cut -d',' -f$idx | cut -d'=' -f$pidx
|
||||
}
|
||||
|
||||
curry get_key get 1
|
||||
curry get_value get 2
|
||||
|
||||
get_key 1 $arg
|
||||
get_value 1 $arg
|
||||
|
||||
seq 1 3 | map lambda a . 'tup $(get_key $a $arg) $(get_value $a $arg)'
|
||||
|
||||
echo 'ls /home' | try λ cmd status ret . 'echo $cmd [$status]; echo $ret'
|
||||
echo '/home' | try λ cmd status ret . 'echo $cmd [$status]; echo $ret'
|
||||
|
||||
seq 1 5 | scanl lambda a b . 'echo $(($a + $b))'
|
||||
seq 1 5 | scanl lambda a b . 'echo $(($a + $b))' | last
|
||||
|
||||
seq 2 3 | map lambda a . 'seq 1 $a' | join , [ ]
|
||||
list a b c | map lambda a . 'echo $a; echo $a | tr a-z A-z' | join , [ ]
|
||||
|
||||
echo 0 | cat - <(curl -s https://raw.githubusercontent.com/ssledz/bash-fun/v1.1.1/src/fun.sh) | \
|
||||
map lambda a . 'list $a' | foldl lambda acc el . 'echo $(($acc + 1))'
|
||||
|
||||
echo 0 | cat - <(curl -s curl -s https://raw.githubusercontent.com/ssledz/bash-fun/v1.1.1/src/fun.sh) \
|
||||
| foldl lambda acc el . 'echo $(($acc + 1))'
|
|
@ -170,9 +170,10 @@ revers_str() {
|
|||
try() {
|
||||
local f="$@"
|
||||
local cmd=$(cat -)
|
||||
ret="$(2>&1 $cmd)"
|
||||
local status=$?
|
||||
list "$cmd" $status $(list $ret | join \#) | $f
|
||||
local ret=$(2>&1 eval "$cmd"; echo $?)
|
||||
local cnt=$(list $ret | wc -l)
|
||||
local status=$(list $ret | last)
|
||||
list "$cmd" $status $(list $ret | take $((cnt - 1)) | join \#) | $f
|
||||
}
|
||||
|
||||
ret() {
|
||||
|
|
Loading…
Reference in a new issue