Merge branch 'develop'

This commit is contained in:
Sławomir Śledź 2019-10-01 00:37:03 +02:00
commit b783ac9e8f
3 changed files with 129 additions and 22 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Sławomir Śledź
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

112
README.md
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
@ -360,6 +431,21 @@ processNames adam monika s slawek d daniel Bartek j k
Adam,Monika,Slawek,Daniel,Bartek Adam,Monika,Slawek,Daniel,Bartek
``` ```
# Running tests
```bash
cd test
./test_runner
```
# Contribution guidelines
Feel free to ask questions in chat, open issues, or contribute by creating pull requests.
In order to create a pull request
* checkout develop branch
* introduce your changes
* submit pull request
# Resources # Resources
* [Inspiration](https://quasimal.com/posts/2012-05-21-funsh.html) * [Inspiration](https://quasimal.com/posts/2012-05-21-funsh.html)

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