Skip to content

Commit f5254a8

Browse files
committed
use less(b, a) for greater(a, b), see also #62
equality test is a problem for some types, which is to say, wrong :)
1 parent ed75c38 commit f5254a8

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

typewriters/genwriter/templates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func (rcv {{.Plural}}) IsSortedBy(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{
309309
// SortByDesc returns a new, descending-ordered {{.Plural}} slice, determined by a func defining ‘less’. See: http://clipperhouse.github.io/gen/#SortBy
310310
func (rcv {{.Plural}}) SortByDesc(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{{.Name}}) bool) {{.Plural}} {
311311
greater := func(a, b {{.Pointer}}{{.Name}}) bool {
312-
return a != b && !less(a, b)
312+
return less(b, a)
313313
}
314314
return rcv.SortBy(greater)
315315
}
@@ -320,7 +320,7 @@ func (rcv {{.Plural}}) SortByDesc(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{
320320
// 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
321321
func (rcv {{.Plural}}) IsSortedByDesc(less func({{.Pointer}}{{.Name}}, {{.Pointer}}{{.Name}}) bool) bool {
322322
greater := func(a, b {{.Pointer}}{{.Name}}) bool {
323-
return a != b && !less(a, b)
323+
return less(b, a)
324324
}
325325
return rcv.IsSortedBy(greater)
326326
}

typewriters/genwriter/test/thing_gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (rcv Things) IsSortedBy(less func(Thing, Thing) bool) bool {
106106
// 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
107107
func (rcv Things) IsSortedByDesc(less func(Thing, Thing) bool) bool {
108108
greater := func(a, b Thing) bool {
109-
return a != b && !less(a, b)
109+
return less(b, a)
110110
}
111111
return rcv.IsSortedBy(greater)
112112
}
@@ -185,7 +185,7 @@ func (rcv Things) SortBy(less func(Thing, Thing) bool) Things {
185185
// SortByDesc returns a new, descending-ordered Things slice, determined by a func defining ‘less’. See: http://clipperhouse.github.io/gen/#SortBy
186186
func (rcv Things) SortByDesc(less func(Thing, Thing) bool) Things {
187187
greater := func(a, b Thing) bool {
188-
return a != b && !less(a, b)
188+
return less(b, a)
189189
}
190190
return rcv.SortBy(greater)
191191
}

0 commit comments

Comments
 (0)