Skip to content

Commit

Permalink
small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
makiuchi-d committed Sep 1, 2024
1 parent 4297933 commit b1ec5b1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 4 additions & 2 deletions elementat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ func ElementAt[T any, E IEnumerable[T]](src E, n int) (def T, err error) {
// ElementAtOrDefault returns the element at a specified index in a sequence or a default value if the index is out of range.
func ElementAtOrDefault[T any, E IEnumerable[T]](src E, n int) (T, error) {
v, err := ElementAt(src, n)
if isOutOfRange(err) {
err = nil
if err != nil {
if isOutOfRange(err) {
err = nil
}
}
return v, err
}
6 changes: 4 additions & 2 deletions last.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ func Last[T any, E IEnumerable[T]](src E) (def T, _ error) {
// LastOrDefault returns the last element of a sequence that satisfies a condition, or a specified default value if no such element is found.
func LastOrDefault[T any, E IEnumerable[T]](src E, defaultValue T) (T, error) {
v, err := Last(src)
if isInvalidOperation(err) {
return defaultValue, nil
if err != nil {
if isInvalidOperation(err) {
return defaultValue, nil
}
}
return v, err
}
3 changes: 0 additions & 3 deletions max.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ func Max[T constraints.Ordered, E IEnumerable[T]](src E) (def T, _ error) {
}
return def, err
}
if err != nil {
return def, err
}
if v > max {
max = v
}
Expand Down
3 changes: 0 additions & 3 deletions min.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ func Min[T constraints.Ordered, E IEnumerable[T]](src E) (def T, _ error) {
}
return def, err
}
if err != nil {
return def, err
}
if v < min {
min = v
}
Expand Down

0 comments on commit b1ec5b1

Please sign in to comment.