You could save a fair amount of typing and eyestrain by not replicating the
type params for types, in their methods:
type Vector(type T) []T
func (v *Vector) Push(x v.T) { *v = append(*v, x) }
////////////
type Map(type K, V) struct {
root *node(K, V)
compare func(K, K) int
}
func (m *Map) InOrder() *Iterator(m.K, m.V) {
type kv = keyValue(m.K, m.V) // convenient shorthand
sender, receiver := chans.Ranger(kv)()
var f func(*node(m.K, m.V)) bool
...
}
Could also just have the bare type param name without the field-like specifier
(e.g., K, V instead of m.K, m.V) but that makes it less obvious what K and V
are -- m.K makes it clear that K is something I can find if I look at the
definition of the type of m.
This also enforces consistent naming of type parameters across all methods.
- Randy
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/2605713E-73F3-4332-911D-D41EAE4DAF6A%40gmail.com.