Merge pull request #1 from ssledz/master

sync with upstream
This commit is contained in:
Tom Poindexter 2019-10-02 16:54:02 -06:00 committed by GitHub
commit da8e3ca3cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 23 deletions

View file

@ -1 +1 @@
2.3
2.4

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
|||||||
|------|------|------|------|------|------|
|**plus**|**append**|**buff**|**curry**|**div**|**drop**|
|**factorial**|**filter**|**foldl**|**foldr**|**head**|**join**|
|**lambda**|**last**|**list**|**map**|**mod**|**mul**|
|**prepend**|**product**|**ret**|**revers_str**|**revers**|**scanl**|
|**splitc**|**strip**|**sub**|**sum**|**tail**|**take**|
|**catch**|**try**|**tupl**|**tupr**|**tup**|**tupx**|
|**unlist**|**zip**|**λ**|**with_trampoline**|**res**|**call**|
|**append**|**buff**|**call**|**catch**|**curry**|**div**|
|**drop**|**dropw**|**factorial**|**filter**|**foldl**|**foldr**|
|**isint**|**isempty**|**isfile**|**isnonzerofile**|**isreadable**|**iswritable**|
|**isdir**|**join**|**lambda**|**last**|**lhead**|**list**|
|**ltail**|**lzip**|**map**|**maybe**|**maybemap**|**maybevalue**|
|**mod**|**mul**|**not**|**ntup**|**ntupl**|**ntupr**|
|**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*
@ -34,17 +38,17 @@ $ list 1 2 3 4 5 | unlist
1 2 3 4 5
```
## *take/drop/tail/head/last*
## *take/drop/ltail/lhead/last*
```bash
$ list 1 2 3 4 | drop 2
3
4
$ list 1 2 3 4 5 | head
$ list 1 2 3 4 5 | lhead
1
$ list 1 2 3 4 | tail
$ list 1 2 3 4 | ltail
2
3
4
@ -190,6 +194,30 @@ one
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*
```bash
@ -205,10 +233,10 @@ $ seq 1 10 | buff λ a b c d e . 'echo $(($a + $b + $c + $d + $e))'
40
```
## *zip*
## *lzip*
```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)
(b,2)
(c,3)
@ -218,7 +246,7 @@ $ list a b c d e f | zip $(seq 1 10)
```
```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
```
@ -244,6 +272,49 @@ $ seq 1 3 | map λ a . 'inc $a'
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*
```bash
@ -360,6 +431,21 @@ processNames adam monika s slawek d daniel Bartek j k
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
* [Inspiration](https://quasimal.com/posts/2012-05-21-funsh.html)

View file

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