Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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`.