lamda
所属分类:人工智能/神经网络/深度学习
开发工具:Lua
文件大小:5KB
下载次数:0
上传日期:2018-12-26 08:36:18
上 传 者:
sh-1993
说明: lamda,Lua的函数式编程库,灵感来自Ramda。
(lamda,A functional programming library for Lua, inspired by Ramda.)
文件列表:
.circleci (0, 2018-12-26)
.circleci\config.yml (2437, 2018-12-26)
.luacheckrc (22, 2018-12-26)
.luacov (44, 2018-12-26)
LICENSE (1070, 2018-12-26)
lamda-dev-1.rockspec (377, 2018-12-26)
spec (0, 2018-12-26)
spec\lamda_spec.lua (2943, 2018-12-26)
src (0, 2018-12-26)
src\lamda.lua (2090, 2018-12-26)
# lamda
[![CircleCI](https://circleci.com/gh/helpermethod/lamda.svg?style=svg)](https://circleci.com/gh/helpermethod/lamda)
[![Coverage Status](https://coveralls.io/repos/github/helpermethod/lamda/badge.svg?branch=master)](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
end
local function square(n)
return n ^ 2
end
local 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
end
local 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}
```
近期下载者:
相关文件:
收藏者: