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

add_vertex! should return the added vertex.

Open chelate opened this issue 3 years ago • 3 comments

So I often write code like

add_vertex!(tree) # returns "true" for some reason ???
v = last(vertices(tree))
...

wouldn't it be great if add_vertex! returned something useful, and guaranteed to be the fresh vertex added, instead of a boolean that I can't imagine a use for? PROPOSAL

v = add_vertex!(tree) #new vertex is the return value!

Let me know if I'm missing something. If people love that boolean (Why???) we can always pass it as the first argument but on the whole this would just be way better.

chelate avatar Apr 29 '22 13:04 chelate

I agree that returning the created vertex would be great, but that would be a big breaking change... Maybe we can consider it for a 2.0 release ?

etiennedeg avatar May 02 '22 13:05 etiennedeg

That would indeed be a breaking change, but it is also very useful, as the current behavior always assumes that the added vertex has the identifier nv(g). In the meantime we could change the functions to something like:

add_vertex!(g; return_added_vertices=false)
add_vertices!(g; return_added_vertices=false)

and if return_added_vertices is true, we would return the added vertices.

simonschoelly avatar May 03 '22 05:05 simonschoelly

How about starting a roadmap for 2.0 with big breaking changes we would like to see happen? I have a few of my own, eg. #77

gdalle avatar May 13 '22 11:05 gdalle