cadr
function cadr( arr ) --> val
Description
Returns the second value of an array table. Useful for methods with multiple return values.
Parameters
- arr
-
An array table with two or more values.
Return Values
- val
-
The second value from arr, if no second value exist returns the function nil.
Code
--ZFUNC-cadr-v1 local function cadr( arr ) --> val if not arr then return nil end return arr[ 2 ] end return cadr
Examples
local t = require( "taptest" ) local cadr = require( "cadr" ) local function beatles() return "John", "Paul", "George", "Ringo" end t( cadr(), nil ) t( cadr{ 1.0 }, nil ) t( cadr{ "a", "b" }, "b" ) t( cadr{ "a", "b", "c" }, "b" ) t( cadr{ beatles() }, "Paul" ) t()