pathedges

function pathedges( path ) --> edges

Description

Splits a path into single edges.

Parameters

path

A sequence of nodes.

Return Values

edges

An array table with the edges.

Code

--ZFUNC-pathedges-v1
local function pathedges( path ) --> edges
   local edges = {}
   if #path < 2 then return edges end
   for n = 2, #path do
      local i = n - 1
      table.insert( edges, { path[ i ], path[ n ] } )
   end
   return edges
end

return pathedges

Examples

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

t.same( pathedges{}, {} )
t.same( pathedges{ "a" }, {} )
t.same( pathedges{ "a", "b" }, { { "a", "b" } } )
t.same( pathedges{ "a", "b", "c" }, { { "a", "b" }, { "b", "c" } } )

t.done()