Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Last active December 17, 2015 15:09
Show Gist options
  • Save jordanorelli/5629733 to your computer and use it in GitHub Desktop.
Save jordanorelli/5629733 to your computer and use it in GitHub Desktop.
// the method definition Less is any method on type T such that the signature of the method is `(T) bool`.
type Sortable interface {
Less(kin) bool
}
// MySortable *does* satisfy Sortable
type MySortable struct {
// ...
}
// this is a valid use of a *kin* type
func (m MySortable) Less(other MySortable) bool {
// ...
}
// SomeOtherSortablt also *does* satisfy Sortable
type SomeOtherSortable struct {
// ...
}
func (s SomeOtherSortable) Less(other SomeOtherSortable) bool {
// ...
}
// Notice here that the method Less on SomeOtherSortable could not take a parameter of type MySortable.
// this is totally *not* what I mean.
type NotTheSameThing struct {
}
// this does *not* satisfy Sortable, because the one parameter of Less is not of the same concrete type as the receiver.
func (n NotTheSameThing) Less(other interface{}) bool {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment