I would like to define a method on []T
, where T
is a type I defined.
It looks like i have to define a new type to do this, but that stops me from using all the builtin functions for slices on this new type (such as len
).
Is the go way of doing this to just make ordinary functions, rather than methods? (Kinda like how append()
could be a method, but isn't?)
You can define a slice type:
type MySliceType []SomeType
MySliceType
.MySliceType
.You can't, however, monkeypatch []SomeType
's methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With