]> Cypherpunks repositories - gostls13.git/commitdiff
sort: move example to package level and simplify further
authorAndrew Gerrand <adg@golang.org>
Mon, 16 Sep 2013 03:02:01 +0000 (13:02 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 16 Sep 2013 03:02:01 +0000 (13:02 +1000)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13634044

src/pkg/sort/example_interface_test.go

index 2b55ebfc53c71f2491d5ac98cf49a8fa532fcafb..442204ea9eb93949e91df2b5fee7d553c5ce11a4 100644 (file)
@@ -20,18 +20,18 @@ func (p Person) String() string {
 
 // ByAge implements sort.Interface for []Person based on
 // the Age field.
-type ByAge []*Person
+type ByAge []Person
 
 func (a ByAge) Len() int           { return len(a) }
 func (a ByAge) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
 func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age }
 
-func ExampleInterface() {
-       people := []*Person{
-               &Person{Name: "Bob", Age: 31},
-               &Person{Name: "John", Age: 42},
-               &Person{Name: "Michael", Age: 17},
-               &Person{Name: "Jenny", Age: 26},
+func Example() {
+       people := []Person{
+               {"Bob", 31},
+               {"John", 42},
+               {"Michael", 17},
+               {"Jenny", 26},
        }
 
        fmt.Println(people)