lots more generics

This commit is contained in:
Jesse Duffield
2022-03-19 15:36:46 +11:00
parent c7a629c440
commit eda8f4a5d4
19 changed files with 384 additions and 299 deletions

View File

@@ -1,8 +1,6 @@
package filetree
import (
"sort"
)
import "github.com/jesseduffield/generics/slices"
type INode interface {
IsNil() bool
@@ -27,19 +25,17 @@ func sortChildren(node INode) {
return
}
children := node.GetChildren()
sortedChildren := make([]INode, len(children))
copy(sortedChildren, children)
sortedChildren := slices.Clone(node.GetChildren())
sort.Slice(sortedChildren, func(i, j int) bool {
if !sortedChildren[i].IsLeaf() && sortedChildren[j].IsLeaf() {
slices.SortFunc(sortedChildren, func(a, b INode) bool {
if !a.IsLeaf() && b.IsLeaf() {
return true
}
if sortedChildren[i].IsLeaf() && !sortedChildren[j].IsLeaf() {
if a.IsLeaf() && !b.IsLeaf() {
return false
}
return sortedChildren[i].GetPath() < sortedChildren[j].GetPath()
return a.GetPath() < b.GetPath()
})
// TODO: think about making this in-place