Last active
December 17, 2015 15:09
-
-
Save jordanorelli/5629733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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