Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify Empty returns zero value #543

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ subset := lo.Without([]int{0, 2, 10}, 0, 1, 2, 3, 4, 5)

### WithoutEmpty

Returns slice excluding empty values.
Returns slice excluding zero values.

```go
subset := lo.WithoutEmpty([]int{0, 2, 10})
Expand Down Expand Up @@ -2788,7 +2788,7 @@ elements, ok := lo.FromAnySlice([]any{"foobar", "42"})

### Empty

Returns an empty value.
Returns the [zero value](https://go.dev/ref/spec#The_zero_value).

```go
lo.Empty[int]()
Expand Down
2 changes: 1 addition & 1 deletion intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func Without[T comparable, Slice ~[]T](collection Slice, exclude ...T) Slice {
return result
}

// WithoutEmpty returns slice excluding empty values.
// WithoutEmpty returns slice excluding zero values.
//
// Deprecated: Use lo.Compact instead.
func WithoutEmpty[T comparable, Slice ~[]T](collection Slice) Slice {
Expand Down
2 changes: 1 addition & 1 deletion type_manipulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func FromAnySlice[T any](in []any) (out []T, ok bool) {
return result, true
}

// Empty returns an empty value.
// Empty returns the zero value (https://go.dev/ref/spec#The_zero_value).
func Empty[T any]() T {
var zero T
return zero
Expand Down
2 changes: 2 additions & 0 deletions type_manipulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func TestEmpty(t *testing.T) {
is.Empty(Empty[int64]())
is.Empty(Empty[test]())
is.Empty(Empty[chan string]())
is.Nil(Empty[[]int]())
is.Nil(Empty[map[string]int]())
}

func TestIsEmpty(t *testing.T) {
Expand Down