diff --git a/README.md b/README.md index b53f101..5b8b965 100644 --- a/README.md +++ b/README.md @@ -121,15 +121,6 @@ exist in the table. lume.find({"a", "b", "c"}, "b") -- Returns 2 ``` -### lume.once(fn, ...) -Returns a wrapper function to `fn` which takes the supplied arguments. The -wrapper function will call `fn` on the first call and do nothing on any -subsequent calls. -```lua -local f = lume.once(print, "Hello") -f() -- Prints "Hello" -f() -- Does nothing -``` ### lume.slice(t [, i [, j]]) Mimics the behaviour of Lua's `string.sub`, but operates on an array rather @@ -149,6 +140,16 @@ local f = lume.fn(print, "Hello") f() -- Prints "Hello" ``` +### lume.once(fn, ...) +Returns a wrapper function to `fn` which takes the supplied arguments. The +wrapper function will call `fn` on the first call and do nothing on any +subsequent calls. +```lua +local f = lume.once(print, "Hello") +f() -- Prints "Hello" +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. diff --git a/lume.lua b/lume.lua index a61a774..274f7dd 100644 --- a/lume.lua +++ b/lume.lua @@ -7,7 +7,7 @@ -- under the terms of the MIT license. See LICENSE for details. -- -local lume = { _version = "1.0.7" } +local lume = { _version = "1.0.8" } function lume.clamp(x, min, max) @@ -144,15 +144,6 @@ function lume.find(t, value) end -function lume.once(fn, ...) - local arg = {...} - return function() - if arg == nil then return end - fn(unpack(arg)) - arg = nil - end -end - function lume.slice(t, i, j) i = i or 1 @@ -174,7 +165,18 @@ end function lume.fn(fn, ...) local arg = {...} - return function() fn(unpack(arg)) end + return function() return fn(unpack(arg)) end +end + + +function lume.once(fn, ...) + local arg = {...} + return function() + if arg == nil then return end + local rtn = {fn(unpack(arg))} + arg = nil + return unpack(rtn) + end end