Skip to content

Commit

Permalink
Added sort and limit primitives to object slices
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed May 17, 2023
1 parent bb4fadb commit b7b64d4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/engine/objectslice.go
Expand Up @@ -196,3 +196,22 @@ func (os *ObjectSlice) Sort(attr Attribute, reverse bool) {

sort.Slice(os.objects, orderf)
}

func (os *ObjectSlice) SortFunc(lessthan func(o, o2 *Object) bool) {
sort.Slice(os.objects, func(i int, j int) bool {
return lessthan(os.objects[i], os.objects[j])
})
}

func (os *ObjectSlice) Limit(count int) {
if count >= 0 {
if count > len(os.objects) {
os.objects = os.objects[:count]
}
} else {
count = -count
if count > len(os.objects) {
os.objects = os.objects[len(os.objects)-count:]
}
}
}

0 comments on commit b7b64d4

Please sign in to comment.