mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Changed args for lume.any/all(), fixed README.md
* The functions lume.any() and lume.all() now have a default function if one is not provided -- their default behaviour with a single argument now matches that of Python. * Updated README.md to reflect changes * Fixed typo in lume.any()'s example in README.md * Incremented version revision number
This commit is contained in:
parent
50eb3d9f52
commit
e018498a0d
16
README.md
16
README.md
@ -66,18 +66,20 @@ with the resulting values.
|
|||||||
lume.map({1, 2, 3}, function(x) return x * 2 end) -- Returns {2, 4, 6}
|
lume.map({1, 2, 3}, function(x) return x * 2 end) -- Returns {2, 4, 6}
|
||||||
```
|
```
|
||||||
|
|
||||||
### lume.all(t, fn)
|
### lume.all(t [, fn])
|
||||||
Calls `fn` on each value in `t` table and returns true if all the calls to `fn`
|
Returns true if all the values in `t` table are true. If a `fn` function is
|
||||||
return true.
|
supplied it is called on each value, true is returned if all of the calls to
|
||||||
|
`fn` return true.
|
||||||
```lua
|
```lua
|
||||||
lume.all({1, 2, 1}, function(x) return x == 1 end) -- Returns false
|
lume.all({1, 2, 1}, function(x) return x == 1 end) -- Returns false
|
||||||
```
|
```
|
||||||
|
|
||||||
### lume.any(t, fn)
|
### lume.any(t [, fn])
|
||||||
Calls `fn` on each value in `t` table and returns true if any of the
|
Returns true if any of the values in `t` table are true. If a `fn` function is
|
||||||
calls to `fn` return true.
|
supplied it is called on each value, true is returned if any of the calls to
|
||||||
|
`fn` return true.
|
||||||
```lua
|
```lua
|
||||||
lume.all({1, 2, 1}, function(x) return x == 1 end) -- Returns true
|
lume.any({1, 2, 1}, function(x) return x == 1 end) -- Returns true
|
||||||
```
|
```
|
||||||
|
|
||||||
### lume.reduce(t, fn, first)
|
### lume.reduce(t, fn, first)
|
||||||
|
4
lume.lua
4
lume.lua
@ -7,7 +7,7 @@
|
|||||||
-- under the terms of the MIT license. See LICENSE for details.
|
-- under the terms of the MIT license. See LICENSE for details.
|
||||||
--
|
--
|
||||||
|
|
||||||
local lume = { _version = "1.0.3" }
|
local lume = { _version = "1.0.4" }
|
||||||
|
|
||||||
|
|
||||||
function lume.clamp(x, min, max)
|
function lume.clamp(x, min, max)
|
||||||
@ -87,6 +87,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.all(t, fn)
|
function lume.all(t, fn)
|
||||||
|
fn = fn or function(x) return x end
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if not fn(v) then return false end
|
if not fn(v) then return false end
|
||||||
end
|
end
|
||||||
@ -95,6 +96,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.any(t, fn)
|
function lume.any(t, fn)
|
||||||
|
fn = fn or function(x) return x end
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if fn(v) then return true end
|
if fn(v) then return true end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user