Fixing examples & documentation + adding example of usage to documentation.

This commit is contained in:
Sławomir Śledź 2019-10-01 00:02:34 +02:00
parent 540840e9d2
commit b590285ec9
2 changed files with 93 additions and 22 deletions

View file

@ -14,13 +14,17 @@ seq 1 4 | sum
# Functions overview # Functions overview
||||||| |||||||
|------|------|------|------|------|------| |------|------|------|------|------|------|
|**plus**|**append**|**buff**|**curry**|**div**|**drop**| |**append**|**buff**|**call**|**catch**|**curry**|**div**|
|**factorial**|**filter**|**foldl**|**foldr**|**head**|**join**| |**drop**|**dropw**|**factorial**|**filter**|**foldl**|**foldr**|
|**lambda**|**last**|**list**|**map**|**mod**|**mul**| |**isint**|**isempty**|**isfile**|**isnonzerofile**|**isreadable**|**iswritable**|
|**prepend**|**product**|**ret**|**revers_str**|**revers**|**scanl**| |**isdir**|**join**|**lambda**|**last**|**lhead**|**list**|
|**splitc**|**strip**|**sub**|**sum**|**tail**|**take**| |**ltail**|**lzip**|**map**|**maybe**|**maybemap**|**maybevalue**|
|**catch**|**try**|**tupl**|**tupr**|**tup**|**tupx**| |**mod**|**mul**|**not**|**ntup**|**ntupl**|**ntupr**|
|**unlist**|**zip**|**λ**|**with_trampoline**|**res**|**call**| |**ntupx**|**peek**|**plus**|**prepend**|**product**|**ret**|
|**res**|**revers**|**revers_str**|**scanl**|**splitc**|**strip**|
|**stripl**|**stripr**|**sub**|**sum**|**take**|**try**|
|**tup**|**tupl**|**tupr**|**tupx**|**unlist**|**λ**|
|**with_trampoline**|
## *list/unlist* ## *list/unlist*
@ -34,17 +38,17 @@ $ list 1 2 3 4 5 | unlist
1 2 3 4 5 1 2 3 4 5
``` ```
## *take/drop/tail/head/last* ## *take/drop/ltail/lhead/last*
```bash ```bash
$ list 1 2 3 4 | drop 2 $ list 1 2 3 4 | drop 2
3 3
4 4
$ list 1 2 3 4 5 | head $ list 1 2 3 4 5 | lhead
1 1
$ list 1 2 3 4 | tail $ list 1 2 3 4 | ltail
2 2
3 3
4 4
@ -190,6 +194,30 @@ one
2 2
``` ```
## *ntup/ntupx/ntupl/ntupr*
```bash
$ ntup a 1 b 2 c 3
(YQo=,MQo=,Ygo=,Mgo=,Ywo=,Mwo=)
$ echo '(YQo=,MQo=,Ygo=,Mgo=,Ywo=,Mwo=)' | ntupx 3
b
$ ntup 'foo bar' 1 one 1
(Zm9vIGJhcgo=,MQo=,b25lCg==,MQo=)
$ echo '(Zm9vIGJhcgo=,MQo=,b25lCg==,MQo=)' | ntupx 1
foo bar
```
```bash
$ ntupl $(ntup 'foo bar' 1 one 2)
foo bar
$ ntupr $(ntup 'foo bar' 1 one 2)
2
```
## *buff* ## *buff*
```bash ```bash
@ -205,10 +233,10 @@ $ seq 1 10 | buff λ a b c d e . 'echo $(($a + $b + $c + $d + $e))'
40 40
``` ```
## *zip* ## *lzip*
```bash ```bash
$ list a b c d e f | zip $(seq 1 10) $ list a b c d e f | lzip $(seq 1 10)
(a,1) (a,1)
(b,2) (b,2)
(c,3) (c,3)
@ -218,7 +246,7 @@ $ list a b c d e f | zip $(seq 1 10)
``` ```
```bash ```bash
$ list a b c d e f | zip $(seq 1 10) | last | tupr $ list a b c d e f | lzip $(seq 1 10) | last | tupr
6 6
``` ```
@ -244,6 +272,49 @@ $ seq 1 3 | map λ a . 'inc $a'
4 4
``` ```
## *peek*
```bash
$ list 1 2 3 \
| peek lambda a . echo 'dbg a : $a' \
| map lambda a . 'mul $a 2' \
| peek lambda a . echo 'dbg b : $a' \
| sum
dbg a : 1
dbg a : 2
dbg a : 3
dbg b : 2
dbg b : 4
dbg b : 6
12
```
```bash
$ a=$(seq 1 4 | peek lambda a . echo 'dbg: $a' | sum)
dbg: 1
dbg: 2
dbg: 3
dbg: 4
$ echo $a
10
```
## *maybe/maybemap/maybevalue*
TODO
## *not/isint/isempty*
TODO
## *isfile/isnonzerofile/isreadable/iswritable/isdir*
TODO
## *try/catch* ## *try/catch*
```bash ```bash

View file

@ -1,26 +1,25 @@
#!/bin/bash #!/bin/bash
source ../src/fun.sh source ../src/fun.sh
seq 1 4 | sum seq 1 4 | sum
seq 1 4 | product seq 1 4 | product
factorial 4 factorial 4
seq 1 4 | scanl lambda a b . 'echo $(add $a $b)' seq 1 4 | scanl lambda a b . 'echo $(plus $a $b)'
echo map mul echo map mul
seq 1 4 | map lambda a . 'echo $(mul $a 2)' seq 1 4 | map lambda a . 'echo $(mul $a 2)'
echo map sub echo map sub
seq 1 4 | map lambda a . 'echo $(sub $a 2)' seq 1 4 | map lambda a . 'echo $(sub $a 2)'
echo map add echo map plsu
seq 1 4 | map lambda a . 'echo $(add $a 2)' seq 1 4 | map lambda a . 'echo $(plus $a 2)'
echo map div echo map div
seq 1 4 | map lambda a . 'echo $(div $a 2)' seq 1 4 | map lambda a . 'echo $(div $a 2)'
echo map mod echo map mod
seq 1 4 | map lambda a . 'echo $(mod $a 2)' seq 1 4 | map lambda a . 'echo $(mod $a 2)'
echo 'list & head' echo 'list & head'
list 1 2 3 4 5 | head list 1 2 3 4 5 | lhead
list {1..2} | append {3..4} | prepend {99..102} list {1..2} | append {3..4} | prepend {99..102}
list {1..2} | unlist list {1..2} | unlist
list {1..10} | head list {1..10} | lhead
list {1..10} | drop 7 list {1..10} | drop 7
list {1..10} | take 3 list {1..10} | take 3
list {1..10} | last list {1..10} | last
@ -83,10 +82,10 @@ seq 1 10 | buff lambda a b . 'echo $(($a + $b))'
echo 'XX' echo 'XX'
seq 1 10 | buff lambda a b c d e . 'echo $(($a + $b + $c + $d + $e))' 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) list a b c d e f | lzip $(seq 1 10)
echo echo
list a b c d e f | zip $(seq 1 10) | last | tupr list a b c d e f | lzip $(seq 1 10) | last | tupr
arg='[key1=value1,key2=value2,key3=value3]' arg='[key1=value1,key2=value2,key3=value3]'
get() { get() {
@ -155,5 +154,6 @@ echo Factorial test
time factorial 30 time factorial 30
time factorial_trampoline 30 time factorial_trampoline 30
time factorial 60 # would be error
#time factorial 60
time factorial_trampoline 60 time factorial_trampoline 60