unwrap

function unwrap( arr [, i [, j]] ) --> ...

Description

Returns the elements from the given list. Implemented as wrapper function around unpack or table.unpack.

Parameters

arr

Source array table with the elements.

i

The index of the first element. By default is the value 1.

j

The index of the last element. By default is the value #arr.

Return Values

Elements from the given array table.

Code

--ZFUNC-unwrap-v1
local function unwrap( arr, i, j ) --> ...
   local unpack = unpack or table.unpack
   return unpack( arr, i, j )
end

return unwrap

Example

local t = require( "taptest" )
local unwrap = require( "unwrap" )

two, four, eight = unwrap( { 2, 4, 8 } )
t( two, 2 )
t( four, 4 )
t( eight, 8 )

three, four, five = unwrap( { 1, 2, 3, 4, 5, 6, 7 }, 3, 5 )
t( three, 3 )
t( four, 4 )
t( five, 5 )

t()