Graphs.jl icon indicating copy to clipboard operation
Graphs.jl copied to clipboard

Convert a Vector{Integer} to Vector{Edge} function

Open filchristou opened this issue 2 years ago • 1 comments

Locally I very often use the following function to convert Vectors of Integers to Vector of Edges.

edgeify(p::Vector{T}) where T<:Integer = map(Edge , zip(p, p[2:end]));

As a result it ends up being defined in many local packages. Do you think it would make sense to have something similar in Graphs.jl ?

Of course it would be nice to probably change the signature to be functional for any E<:AbstractEdge type.

I was also thinking about dispatching the Base.convert function, but maybe we don't want any automatic conversion to take place. What do you think ?

filchristou avatar Aug 11 '22 08:08 filchristou

To clarify for onlookers, this function takes a path represented as a list of vertices and returns the correponding list of edges. In principle this would make sense, but as you noticed the current implementation only works for the Edge type and not for any edgetype. The trouble is that some edgetypes might require more than source and destination within the constructors (we ran into this in #116)

gdalle avatar Nov 20 '22 20:11 gdalle