collectk

function collectk( ... ) --> arr

Description

Util function to collect all keys during the generic for loop for the list of expressions(). The key is the first value inside the generic for loop.

Parameters

One or more expressions that will be passed to the generic for loop.

Return Values

arr

Array table that contains all the keys.

Code

--ZFUNC-collectk-v1
local function collectk( ... ) --> arr
   local arr = {}
   for v in ... do
      table.insert( arr, v )
   end
   return arr
end

return collectk

Examples

local t = require( "tapered" )
local collectk = require( "collectk" )

local like = require( "like" )

src = { a="x", b="y", c="z" }
keys = collectk( pairs( src ) )
t.ok( like( { "a", "b", "c" }, keys ) )

t.done()

See also