tableize

function tableize( val ) --> tab

Description

Puts val in a table if it is necessary. If val is a table return the function just val.

Parameters

val

The value that should be a table.

Return Values

tab

A table with val as value or val itself when it is a table.

Code

--ZFUNC-tableize-v1
local function tableize( val ) --> tab
   if type( val ) == "table" then
      return val
   else
      return { val }
   end
end

return tableize

Examples

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

t.same( { "root" }, tableize( "root" ) )
t.same( { "root" }, tableize{ "root" } )
t.same( { 1 }, tableize( 1 ) )

t.same( {}, tableize() )
t.same( {}, tableize( nil ) )

t.done()