https://github.com/helpermethod/lamda
A functional programming library for Lua, inspired by Ramda.
https://github.com/helpermethod/lamda
functional-programming lua
Last synced: 6 months ago
JSON representation
A functional programming library for Lua, inspired by Ramda.
- Host: GitHub
- URL: https://github.com/helpermethod/lamda
- Owner: helpermethod
- License: mit
- Created: 2018-09-06T15:15:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-26T08:36:18.000Z (almost 7 years ago)
- Last Synced: 2025-03-26T18:43:51.215Z (6 months ago)
- Topics: functional-programming, lua
- Language: Lua
- Homepage:
- Size: 44.9 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lamda
[](https://circleci.com/gh/helpermethod/lamda)
[](https://coveralls.io/github/helpermethod/lamda?branch=master)A functional programming library for Lua, inspired by [Ramda](https://ramdajs.com/).
## Install
```sh
$ luarocks install lamda
```## Usage
```lua
local lamda = require('lamda')local shout = lamda.pipe(string.upper, function(s) return s .. '!' end)
shout('lamda rocks') -- returns 'LAMDA ROCKS!'
```## API
### flip(fn)
Creates a new function with the order of the first two arguments reversed.
```lua
local join = lamda.flip(table.concat)join(',', {1, 2, 3}) -- returns '1,2,3'
```### join(separator, tbl)
Creates a new string by concatenating all elemements and putting a separator in between.
```lua
lamda.join(',', {1, 2, 3}) -- returns '1,2,3'
```### concat(first_table, second_table)
Creates a new array by concatenating the given arrays.
```lua
lamda.concat({1, 2, 3}, {4, 5, 6}) -- returns {1, 2, 3, 4, 5, 6}
```### pipe(fn, ...)
Creates a new function by composing the given functions from left to right. The first function may have any arity while the remaining functions must be unary.
```lua
local function add(a, b)
return a + b
endlocal function square(n)
return n ^ 2
endlocal add_and_square = lamda.pipe(add, square)
add_and_square(2, 3) -- returns 25
```### partial(fn, ...)
Takes a function `f` and a variable number of arguments and creates a new function `g`. When applied, `g` returns the result of applying `f` to theinitially provided arguments followed by the arguments to `g`.
```lua
local function prepend(first_string, second_string)
return
endlocal add_two = lamda.partial(add, 2)
```### partial_right(fn, ...)
### any_pass(predicate, ...)
### sort(comparator, tbl)
Creates a new array by sorting the given array according to a comparator function. The comparator function receives two arguments and must return `true` if the first argument should come first in the sorted array.
```lua
local numbers = {2, 1, 3}lamda.sort(function(a, b) return a < b end, numbers) -- returns {1, 2, 3}
```