Skip to content

Commit

Permalink
limit fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Orfo committed Nov 8, 2024
1 parent 4cb4522 commit cff67de
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ func (list List[T]) FlatMapToAny(mapper func(T) Steam[any]) Steam[any] {

// Limit restricts the number of elements in the List to the specified limit and returns a new List.
func (list List[T]) Limit(limit int) Steam[T] {
results := make(List[T], 0)
for i := 0; i < len(list) && i < limit; i++ {
results = append(results, list[i])
if limit > list.Count() {
limit = list.Count()
}
results := make(List[T], limit)
copy(results, list[:limit])
return results
}

Expand Down

0 comments on commit cff67de

Please sign in to comment.