Skip to content

millermatt/shuff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shuff

Functional programming utils for bash scripts

Yes, it's ridiculous.

See test/lib/shuff.test.sh for more examples.

Install

Download build/lib/shuff.sh and source it in your script.

API

concat

# use: concat <string0> <string1> <string2> <...>

concat_arrays

dependency: https://stedolan.github.io/jq/

# use: concat_arrays <array 1 as json string> <array 2 as json string>

filter

# use: cat <file with line separated data> | filter <command to receive line data>
# ex:  printf "foo\nbar\n" | filter not_foo
#      function not_foo {
#          if [[ $1 != 'foo' ]]; then
#              echo $1
#          fi
#      }
#  result:
#         bar

map

# use: cat <file with line separated data> | map <command to receive line data>
# ex:  printf "foo\nbar\n" | map echo mapped
#  result:
#         mapped foo
#         mapped bar

map_parallel

# use: cat <file with line separated data> | map <command to receive line data>
# ex:  printf "foo\nbar\n" | map_parallel echo mapped
#  result:
#         mapped foo
#         mapped bar
#  or maybe:
#         mapped bar
#         mapped foo

partial

# use: partial <original function name> <new function name> <params>

partial_right

# use: partial_right <original function name> <new function name> <params>

reduce

# use: cat <file with line separated data> | reduce <initial accumulator value> <command to receive line data>
# ex:  printf "foo\nbar\n" | reduce oof append
#      function append {
#          local line=$1
#          local accumulator=$2
#          if [[ -z $accumulator ]]; then
#              local comma=""
#          else
#              local comma=","
#          fi
#          echo "${accumulator}${comma}${line}"
#      }
#  result:
#         oof,foo,bar

thunk

# like `partial` but never passes in additional arguments on subsequent calls
# https://functionalprogramming.slack.com/archives/C0432GV99/p1559173581072200
# use: thunk <original function name> <new function name> <params>

About

Functional programming utils for shell scripts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published