Skip to content

Commit

Permalink
use less(b, a) for greater(a, b), see also #62
Browse files Browse the repository at this point in the history
equality test is a problem for some types, which is to say, wrong :)
  • Loading branch information
clipperhouse committed Aug 7, 2014
1 parent ed75c38 commit f5254a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions typewriters/genwriter/templates.go
Expand Up @@ -309,7 +309,7 @@ func (rcv {{.Plural}}) IsSortedBy(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{
// SortByDesc returns a new, descending-ordered {{.Plural}} slice, determined by a func defining ‘less’. See: http://clipperhouse.github.io/gen/#SortBy
func (rcv {{.Plural}}) SortByDesc(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{{.Name}}) bool) {{.Plural}} {
greater := func(a, b {{.Pointer}}{{.Name}}) bool {
return a != b && !less(a, b)
return less(b, a)
}
return rcv.SortBy(greater)
}
Expand All @@ -320,7 +320,7 @@ func (rcv {{.Plural}}) SortByDesc(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{
// IsSortedDesc reports whether an instance of {{.Plural}} is sorted in descending order, using the pass func to define ‘less’. See: http://clipperhouse.github.io/gen/#SortBy
func (rcv {{.Plural}}) IsSortedByDesc(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{{.Name}}) bool) bool {
greater := func(a, b {{.Pointer}}{{.Name}}) bool {
return a != b && !less(a, b)
return less(b, a)
}
return rcv.IsSortedBy(greater)
}
Expand Down
4 changes: 2 additions & 2 deletions typewriters/genwriter/test/thing_gen.go
Expand Up @@ -106,7 +106,7 @@ func (rcv Things) IsSortedBy(less func(Thing, Thing) bool) bool {
// IsSortedDesc reports whether an instance of Things is sorted in descending order, using the pass func to define ‘less’. See: http://clipperhouse.github.io/gen/#SortBy
func (rcv Things) IsSortedByDesc(less func(Thing, Thing) bool) bool {
greater := func(a, b Thing) bool {
return a != b && !less(a, b)
return less(b, a)
}
return rcv.IsSortedBy(greater)
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (rcv Things) SortBy(less func(Thing, Thing) bool) Things {
// SortByDesc returns a new, descending-ordered Things slice, determined by a func defining ‘less’. See: http://clipperhouse.github.io/gen/#SortBy
func (rcv Things) SortByDesc(less func(Thing, Thing) bool) Things {
greater := func(a, b Thing) bool {
return a != b && !less(a, b)
return less(b, a)
}
return rcv.SortBy(greater)
}
Expand Down

0 comments on commit f5254a8

Please sign in to comment.