caddr

function caddr( arr ) --> val

Description

Returns the third value of an array table. Useful for methods with multiple return values.

Parameters

arr

An array table with three or more values.

Return Values

val

The third value from arr, if no third value exist returns the function nil.

Code

--ZFUNC-caddr-v1
local function caddr( arr ) --> val
   if not arr then return nil end

   return arr[ 3 ]
end

return caddr

Examples

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

local function beatles()
   return "John", "Paul", "George", "Ringo"
end

t.is( nil, caddr() )
t.is( nil, caddr{ 1.0 } )
t.is( nil, caddr{ "a", "b" } )
t.is( "c", caddr{ "a", "b", "c" } )
t.is( "George", caddr{ beatles() } )

t.done()

Inspired by

See also