Moved position of lume.combine() in readme and other files

This commit is contained in:
rxi 2014-04-03 20:17:31 +01:00
parent 8311519e3f
commit dbd93b3861
3 changed files with 21 additions and 21 deletions

View File

@ -193,6 +193,13 @@ f() -- Prints "Hello"
f() -- Does nothing f() -- Does nothing
``` ```
### lume.time(fn, ...)
Inserts the arguments into function `fn` and calls it. Returns the time in
seconds the function `fn` took to execute followed by `fn`'s returned values.
```lua
lume.time(function(x) return x end, "hello") -- Returns 0, "hello"
```
### lume.combine(...) ### lume.combine(...)
Creates a wrapper function which calls each supplied argument in the order they Creates a wrapper function which calls each supplied argument in the order they
were passed to `lume.combine`. The wrapper function passes its own arguments to were passed to `lume.combine`. The wrapper function passes its own arguments to
@ -203,13 +210,6 @@ local f = lume.combine(function(a, b) print(a + b) end,
f(3, 4) -- Prints "7" then "12" on a new line f(3, 4) -- Prints "7" then "12" on a new line
``` ```
### lume.time(fn, ...)
Inserts the arguments into function `fn` and calls it. Returns the time in
seconds the function `fn` took to execute followed by `fn`'s returned values.
```lua
lume.time(function(x) return x end, "hello") -- Returns 0, "hello"
```
### lume.lambda(str) ### lume.lambda(str)
Takes a string lambda and returns a function. `str` should be a list of Takes a string lambda and returns a function. `str` should be a list of
comma-separated parameters, followed by `->`, followed by the expression which comma-separated parameters, followed by `->`, followed by the expression which

View File

@ -246,6 +246,13 @@ function lume.once(fn, ...)
end end
function lume.time(fn, ...)
local start = os.clock()
local rtn = {fn(...)}
return (os.clock() - start), unpack(rtn)
end
function lume.combine(...) function lume.combine(...)
local funcs = {...} local funcs = {...}
assert(lume.all(funcs, isfunction), "expected all arguments to be functions") assert(lume.all(funcs, isfunction), "expected all arguments to be functions")
@ -255,13 +262,6 @@ function lume.combine(...)
end end
function lume.time(fn, ...)
local start = os.clock()
local rtn = {fn(...)}
return (os.clock() - start), unpack(rtn)
end
local lambda_cache = {} local lambda_cache = {}
function lume.lambda(str) function lume.lambda(str)

View File

@ -249,6 +249,13 @@ tests["lume.once"] = function()
testeq( f(5), nil ) testeq( f(5), nil )
end end
-- lume.time
tests["lume.time"] = function()
local t, a, b, c = lume.time(function(x) return 50, 60, x end, 70)
testeq( type(t), "number" )
testeq( {a, b, c}, {50, 60, 70} )
end
-- lume.combine -- lume.combine
tests["lume.combine"] = function() tests["lume.combine"] = function()
local acc = 0 local acc = 0
@ -259,13 +266,6 @@ tests["lume.combine"] = function()
testeq( acc, 230 ) testeq( acc, 230 )
end end
-- lume.time
tests["lume.time"] = function()
local t, a, b, c = lume.time(function(x) return 50, 60, x end, 70)
testeq( type(t), "number" )
testeq( {a, b, c}, {50, 60, 70} )
end
-- lume.lambda -- lume.lambda
tests["lume.lambda"] = function() tests["lume.lambda"] = function()
testeq( lume.lambda "x->x*x"(10), 100 ) testeq( lume.lambda "x->x*x"(10), 100 )