Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonlydike/functionalshell
some common helpers in functional programming to help you do more with your shell
https://github.com/antonlydike/functionalshell
Last synced: 23 days ago
JSON representation
some common helpers in functional programming to help you do more with your shell
- Host: GitHub
- URL: https://github.com/antonlydike/functionalshell
- Owner: AntonLydike
- Created: 2021-02-17T13:38:41.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-17T13:52:45.000Z (almost 4 years ago)
- Last Synced: 2024-10-30T11:49:34.399Z (2 months ago)
- Language: Shell
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# functional programming for shell scripts
This tool aims to provide functional programming basics like map, reduce, fold, zip etc for shells
Example: `du * | cut -f 1 | reduce (lambda x y : 'math $y + $x')` here we sum over all file sizes using a lambda and the reduce function.
## install
### fish:
include `set -ax fish_function_path /path/to/this/repo/src/fish` somewhere in your fish init## Available functions:
`` can is always a list of zero or more arguments### map
Usage: `map CMD `call `FUNCTION $ARG` for each arg supplied
### coalesce
Usage: `coalesce `prints first non null argument
### reduce
Usage: `reduce CMD [--start=] `Reduce the list: `x0 = start || ""` and `x_n+1 = (CMD $x_n $arg_n)`
### zip
Usage `zip [--cmd=CMD] [ -- [ -- [...]]]``CMD` defaults to `echo`
Returns `CMD $list1_i $list2_i ...` for each entry in the lists. If the list is empty the argument will be an empty string
### lambda
Usage: `lambda ... : `Examples:
```
# create lambda function and save reference to it
set add (lambda x y : 'math $y + $x')
# call it
$add 1 2
# use it
reduce $add (seq 10)
# immediate usage
reduce (lambda x y : 'math $y + $x') (seq 10)
```### curry
Usage: `curry cmd `[curries](https://en.wikipedia.org/wiki/Currying) `cmd` with `list`.