Skip to content

Commit

Permalink
sliceop: use errors.New for constant errors
Browse files Browse the repository at this point in the history
use errors.New instead of fmt.Errorf when the message is a constant
string.
  • Loading branch information
dolmen authored and sbinet committed May 10, 2022
1 parent 40700b8 commit 07f22fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 4 additions & 3 deletions sliceop/f64s/f64s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package f64s

import (
"errors"
"fmt"
"math/rand"
"reflect"
Expand Down Expand Up @@ -35,9 +36,9 @@ func TestMap(t *testing.T) {

func TestTake(t *testing.T) {
var (
errLength = fmt.Errorf("sliceop: length mismatch")
errSortedIndices = fmt.Errorf("sliceop: indices not sorted")
errDuplicateIndices = fmt.Errorf("sliceop: duplicate indices")
errLength = errors.New("sliceop: length mismatch")
errSortedIndices = errors.New("sliceop: indices not sorted")
errDuplicateIndices = errors.New("sliceop: duplicate indices")
)

for _, tc := range []struct {
Expand Down
10 changes: 4 additions & 6 deletions sliceop/sliceop.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
// slices package.
package sliceop // import "go-hep.org/x/hep/sliceop"

import (
"fmt"
)
import "errors"

var (
errLength = fmt.Errorf("sliceop: length mismatch")
errSortedIndices = fmt.Errorf("sliceop: indices not sorted")
errDuplicateIndices = fmt.Errorf("sliceop: duplicate indices")
errLength = errors.New("sliceop: length mismatch")
errSortedIndices = errors.New("sliceop: indices not sorted")
errDuplicateIndices = errors.New("sliceop: duplicate indices")
)

// Filter creates a slice with all the elements x_i of src for which f(x_i) is true.
Expand Down

0 comments on commit 07f22fc

Please sign in to comment.