nth

function nth( n ) --> func

Description

Creates a function that returns the argument that is on position n.

Parameters

n

The index of the parameter that will be returned.

Return Values

func

A new function to extract the value from the parameters.

Code

--ZFUNC-nth-v1
local function nth( n ) --> func
   return function ( ... )
      local tab = { ... }
      return tab[ n ]
   end
end

return nth

Examples

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

func = nth( 2 )
t.is( "b", func( "a", "b", "c" ) )

t.done()

Inspired by