Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
v1.0.4 release prep
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseCoretta committed Jun 17, 2024
1 parent ab47706 commit d812f8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,33 @@ func (r stack) defaultLesser(idx1, idx2 int) bool {
/*
SetLessFunc assigns the provided closure instance to the receiver instance,
thereby allowing effective use of the [Stack.Less] method.
If a nil value, or no values, are submitted, the package-default sorting
mechanism will take precedence.
*/
func (r Stack) SetLessFunc(function func(int, int) bool) Stack {
func (r Stack) SetLessFunc(function ...func(int, int) bool) Stack {
if r.IsInit() {
r.stack.setLessFunc(function)
r.stack.setLessFunc(function...)
}

return r
}

func (r *stack) setLessFunc(function func(int, int) bool) {
func (r *stack) setLessFunc(function ...func(int, int) bool) {
var funk func(int, int) bool
if len(function) > 0 {
if function[0] == nil {
funk = r.defaultLesser
} else {
funk = function[0]
}
} else {
funk = r.defaultLesser
}

if !r.positive(ronly) {
cfg, _ := r.config()
cfg.lss = function
cfg.lss = funk
}

return
Expand Down
2 changes: 2 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,8 @@ func TestStack_codecov(t *testing.T) {
customStack(List().Push(1, `&`)),
customStack(List().Push(`_n`, `?!?`, 5)))
sort.Stable(s)
s.SetLessFunc(nil)
s.SetLessFunc()

s.SetLogLevel(8, 16)
s.UnsetLogLevel(8, 16)
Expand Down

0 comments on commit d812f8d

Please sign in to comment.