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( "taptest" )
local pathedges = require( "pathedges" )
local same = require( "same" )

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

t()