Commit fb25a618 authored by Andriy Lytvynov's avatar Andriy Lytvynov Committed by Russ Cox

sort: fix Example_sortMultiKeys

Old example referenced global var from multiSorter.Sort and ignored it's argument.
Changed one of example calls to actually pass slice to sort.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13551044
parent af2a3193
...@@ -26,6 +26,7 @@ type multiSorter struct { ...@@ -26,6 +26,7 @@ type multiSorter struct {
// Sort sorts the argument slice according to the less functions passed to OrderedBy. // Sort sorts the argument slice according to the less functions passed to OrderedBy.
func (ms *multiSorter) Sort(changes []Change) { func (ms *multiSorter) Sort(changes []Change) {
ms.changes = changes
sort.Sort(ms) sort.Sort(ms)
} }
...@@ -33,8 +34,7 @@ func (ms *multiSorter) Sort(changes []Change) { ...@@ -33,8 +34,7 @@ func (ms *multiSorter) Sort(changes []Change) {
// Call its Sort method to sort the data. // Call its Sort method to sort the data.
func OrderedBy(less ...lessFunc) *multiSorter { func OrderedBy(less ...lessFunc) *multiSorter {
return &multiSorter{ return &multiSorter{
changes: changes, less: less,
less: less,
} }
} }
...@@ -108,11 +108,10 @@ func Example_sortMultiKeys() { ...@@ -108,11 +108,10 @@ func Example_sortMultiKeys() {
OrderedBy(user).Sort(changes) OrderedBy(user).Sort(changes)
fmt.Println("By user:", changes) fmt.Println("By user:", changes)
// multiSorter implements the Sort interface, so we can also do this. // More examples.
sort.Sort(OrderedBy(user, increasingLines)) OrderedBy(user, increasingLines).Sort(changes)
fmt.Println("By user,<lines:", changes) fmt.Println("By user,<lines:", changes)
// More examples.
OrderedBy(user, decreasingLines).Sort(changes) OrderedBy(user, decreasingLines).Sort(changes)
fmt.Println("By user,>lines:", changes) fmt.Println("By user,>lines:", changes)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment