Add docs for ntup, maybe, is* predicates
Updated ntup docs to show nested tuples, and comma safe elements. Added docs for maybe and is* predicates.
This commit is contained in:
parent
da8e3ca3cf
commit
5e1cf52840
1 changed files with 91 additions and 12 deletions
103
README.md
103
README.md
|
@ -197,17 +197,17 @@ one
|
||||||
## *ntup/ntupx/ntupl/ntupr*
|
## *ntup/ntupx/ntupl/ntupr*
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ntup a 1 b 2 c 3
|
$ ntup tuples that $(ntup safely nest)
|
||||||
(YQo=,MQo=,Ygo=,Mgo=,Ywo=,Mwo=)
|
(dHVwbGVzCg==,dGhhdAo=,KGMyRm1aV3g1Q2c9PSxibVZ6ZEFvPSkK)
|
||||||
|
|
||||||
$ echo '(YQo=,MQo=,Ygo=,Mgo=,Ywo=,Mwo=)' | ntupx 3
|
echo '(dHVwbGVzCg==,dGhhdAo=,KGMyRm1aV3g1Q2c9PSxibVZ6ZEFvPSkK)' | ntupx 3 | ntupr
|
||||||
b
|
nest
|
||||||
|
|
||||||
$ ntup 'foo bar' 1 one 1
|
$ ntup 'foo,bar' 1 one 1
|
||||||
(Zm9vIGJhcgo=,MQo=,b25lCg==,MQo=)
|
(Zm9vLGJhcgo=,MQo=,b25lCg==,MQo=)
|
||||||
|
|
||||||
$ echo '(Zm9vIGJhcgo=,MQo=,b25lCg==,MQo=)' | ntupx 1
|
$ echo '(Zm9vLGJhcgo=,MQo=,b25lCg==,MQo=)' | ntupx 1
|
||||||
foo bar
|
foo,bar
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -305,15 +305,94 @@ $ echo $a
|
||||||
|
|
||||||
## *maybe/maybemap/maybevalue*
|
## *maybe/maybemap/maybevalue*
|
||||||
|
|
||||||
TODO
|
```bash
|
||||||
|
$ list Hello | maybe
|
||||||
|
(Just,Hello)
|
||||||
|
|
||||||
|
$ list " " | maybe
|
||||||
|
(Nothing)
|
||||||
|
|
||||||
|
$ list Hello | maybe | maybemap λ a . 'tr oH Oh <<<$a'
|
||||||
|
(Just,hellO)
|
||||||
|
|
||||||
|
$ list " " | maybe | maybemap λ a . 'tr oH Oh <<<$a'
|
||||||
|
(Nothing)
|
||||||
|
|
||||||
|
$ echo bash-fun rocks | maybe | maybevalue DEFAULT
|
||||||
|
bash-fun rocks
|
||||||
|
|
||||||
|
$ echo | maybe | maybevalue DEFAULT
|
||||||
|
DEFAULT
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## *not/isint/isempty*
|
## *not/isint/isempty*
|
||||||
|
|
||||||
TODO
|
```bash
|
||||||
|
$ isint 42
|
||||||
|
true
|
||||||
|
|
||||||
|
$ list blah | isint
|
||||||
|
false
|
||||||
|
|
||||||
|
$ not true
|
||||||
|
false
|
||||||
|
|
||||||
|
$ not isint 777
|
||||||
|
false
|
||||||
|
|
||||||
|
$ list 1 2 "" c d 6 | filter λ a . 'isint $a'
|
||||||
|
1
|
||||||
|
2
|
||||||
|
6
|
||||||
|
|
||||||
|
$ list 1 2 "" c d 6 | filter λ a . 'not isempty $a'
|
||||||
|
1
|
||||||
|
2
|
||||||
|
c
|
||||||
|
d
|
||||||
|
6
|
||||||
|
```
|
||||||
|
|
||||||
## *isfile/isnonzerofile/isreadable/iswritable/isdir*
|
## *isfile/isnonzerofile/isreadable/iswritable/isdir*
|
||||||
|
|
||||||
TODO
|
```bash
|
||||||
|
$ touch /tmp/foo
|
||||||
|
|
||||||
|
$ isfile /tmp/foo
|
||||||
|
true
|
||||||
|
|
||||||
|
$ not iswritable /
|
||||||
|
true
|
||||||
|
|
||||||
|
$ files="/etc/passwd /etc/sudoers /tmp /tmp/foo /no_such_file"
|
||||||
|
|
||||||
|
$ list $files | filter λ a . 'isfile $a'
|
||||||
|
/etc/passwd
|
||||||
|
/etc/sudoers
|
||||||
|
/tmp/foo
|
||||||
|
|
||||||
|
$ list $files | filter λ a . 'isdir $a'
|
||||||
|
/tmp
|
||||||
|
|
||||||
|
$ list $files | filter λ a . 'isreadable $a'
|
||||||
|
/etc/passwd
|
||||||
|
/tmp
|
||||||
|
/tmp/foo
|
||||||
|
|
||||||
|
$ list $files | filter λ a . 'iswritable $a'
|
||||||
|
/tmp
|
||||||
|
/tmp/foo
|
||||||
|
|
||||||
|
$ list $files | filter λ a . 'isnonzerofile $a'
|
||||||
|
/etc/passwd
|
||||||
|
/etc/sudoers
|
||||||
|
/tmp
|
||||||
|
|
||||||
|
$ list $files | filter λ a . 'not isfile $a'
|
||||||
|
/tmp
|
||||||
|
/no_such_file
|
||||||
|
```
|
||||||
|
|
||||||
## *try/catch*
|
## *try/catch*
|
||||||
|
|
||||||
|
@ -449,4 +528,4 @@ In order to create a pull request
|
||||||
|
|
||||||
# Resources
|
# Resources
|
||||||
* [Inspiration](https://quasimal.com/posts/2012-05-21-funsh.html)
|
* [Inspiration](https://quasimal.com/posts/2012-05-21-funsh.html)
|
||||||
* [Functional Programming in Bash](https://medium.com/@joydeepubuntu/functional-programming-in-bash-145b6db336b7)
|
* [Functional Programming in Bash](https://medium.com/@joydeepubuntu/functional-programming-in-bash-145b6db336b7)
|
||||||
|
|
Loading…
Reference in a new issue