Skip to content

Commit

Permalink
Fixed first method, that found elements return error of nil
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyofx committed Aug 19, 2022
1 parent bccbef1 commit 76d5778
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ func (query Queryable[T]) CountIf(predicate func(T) bool) int {
// First return the first element of a collection.
func (query Queryable[T]) First() (T, error) {
var item T
err := ErrorCannotFound
slice := query.ToSlice()
if len(slice) > 0 {
item = slice[0]
err = nil
}
return item, ErrorCannotFound
return item, err
}

// FirstIf return first element of collection satisfy a condition.
Expand Down

0 comments on commit 76d5778

Please sign in to comment.