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

WithAllowZero doesn't work on slice of structs with inner struct #151

Closed
tamirkiviti13 opened this issue Apr 20, 2022 · 0 comments
Closed

Comments

@tamirkiviti13
Copy link

I have the following types:

type Address struct {
	Street  string
	City    string
	Country string
	Zip     int
}

type Person struct {
	Name    string
	Age     int
	Address Address
}

And I have an array of persons:

persons := []Person{
		{
			Name: "name1",
			Age:  21,
			Address: Address{
				Street:  "street1",
				City:    "city1",
				Country: "country1",
				Zip:     0,
			},
		},
		{
			Name: "name2",
			Age:  22,
			Address: Address{
				Street:  "street2",
				City:    "city2",
				Country: "country2",
				Zip:     0,
			},
		},
	}

And I'm trying to extract the an array of the zips from this persons array using funk.Get, and use the WithAllowZero option:

zips := funk.Get(persons, "Address.Zip", funk.WithAllowZero())

The expected result is [0, 0], but I'm getting nil instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants