#fbash.sh: Functional /bin/bash. Functional bash scripting. Forked from https://github.com/mikeplus64/fun.sh
The lambda function represents an anonymous function. The lambda function is used as a predicate for other functions.
eg.,
lambda a b : 'echo $(($a - $b))'
The fold function reduces a list (or other structure) to a single value by "folding" a binary operator (function) between successive elements of the list.
eg.,
list {1..3} | fold lambda a b : 'echo $(($a + $b))'
result:
6
The list function prints each element to a new line in order.
eg.,
list '1' '2' '3'
result:
1
2
3
The reverse list function prints each element to a new line in reverse order.
eg.,
rlist '1' '2' '3'
result:
3
2
1
The strcmp function compares two strings, returning 1 for a match and 0 for no match.
eg.,
strcmp 'hello' 'world'
result:
0
eg.,
strcmp 'hello' 'hello'
result:
1
The filter function compares elements in a list using a given function, in ascending order. A new list is returned containing only list elements that satify the function.
eg.,
list 'hello' 'world' | filter lambda a : 'echo $(strcomp "$a" "hello")'
result:
hello
The match function compares elements in a list using a given function, in ascending order. The first matching element is returned and if no match then nothing is returned.
eg.,
list 'hello' 'world' | match lambda a : 'echo $(strcomp "$a" "world")'
result:
world
The position function compares elements in a list using a given function, in ascending order. The position of the first matching element is returned. Initial position is 0. Nothing is returned for no match.
eg.,
list 'hello' 'world' | position lambda a : 'echo $(strcomp "$a" "hello")'
result:
0