Closed slayer closed 8 years ago
@slayer Did you try using
//go:generate fungen -types Node,Edge
This should work with pointers as well. For instance, if you define a struct like
type Node struct {}
you'll have the methods generated available on a variable of this type and on a pointer to a variable of this type.
@slayer I'm closing this issue. If you think that I've understood your issue incorrectly or if this is still a problem for you, let me know and I'll open this and take a look at it again.
@slayer Please take a look at the slightly modified version at https://play.golang.org/p/Y1ZiBH3EEi
Note that the generated methods don't operate on the members of a list directly. They always return a copy.
I can see how the name of the Each
method can cause some confusion. This method is used when there's a requirement to perform some action for each member of the list, but not ON each member of the list. For example, you might want to loop through a list and print out a message for each of them.
If you want to modify or transform the members of a list in any way, you should use the Map
of PMap
method.
Does this help you?
Reopening for now
Note that the generated methods don't operate on the members of a list directly. They always return a copy.
Sure, that is why I want a pointer version of functions.
My storage has a plurality of interconnected mutable objects (nodes and edges), and I need to go through they and change state. It is no problem with a pointer version unlike with a copy version Thanks
Currently I have done with a type PItem *Item
, but it is a workaround
I see your point. I'll take a closer look at it over the weekend and see how this use case can be best served.
@slayer Could you please check if your original code works with these changes
I've tested the latest changes with various combinations and this seems to be working now.
However, there is an edge case that's not handled - when generating for something like *Node,Node:N
, there seems to be a problem.
@slayer If you can confirm that this satisfies your original requirements, I'll close this issue and open another one for the edge case.
Yes, it works fine. Thanks
Hi
I want to use pointers to my types, like:
//go:generate fungen -types *Node,*Edge
but got error: