Skip to content

Commit

Permalink
fix(module: List): return pointer instead
Browse files Browse the repository at this point in the history
  • Loading branch information
charleypeng committed Aug 15, 2024
1 parent bc00c89 commit 285a133
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (lst *List[T]) Sum() any {
}

// a linq function which returns a predicated list
func (lst *List[T]) Where(predicate func(T) bool) List[T] {
func (lst *List[T]) Where(predicate func(T) bool) *List[T] {
// Estimate the capacity for the result slice
estimatedCapacity := len(lst.Items) / 2
result := make([]T, 0, estimatedCapacity)
Expand All @@ -65,16 +65,16 @@ func (lst *List[T]) Where(predicate func(T) bool) List[T] {
}

wg.Wait()
return *NewList(result)
return NewList(result)
}

// get the array list
func (lst *List[T]) ToArray() []T {
return lst.Items
func (lst *List[T]) ToArray() *[]T {
return &lst.Items
}

// a linq function which returns a predicated list
func WhereT[T any](lst *[]T, predicate func(T) bool) []T {
func WhereT[T any](lst *[]T, predicate func(T) bool) *[]T {

// Estimate the capacity for the result slice
estimatedCapacity := len(*lst) / 2
Expand All @@ -97,5 +97,5 @@ func WhereT[T any](lst *[]T, predicate func(T) bool) []T {
}

wg.Wait()
return result
return &result
}

0 comments on commit 285a133

Please sign in to comment.