thoas / go-funk

A modern Go utility library which provides helpers (map, find, contains, filter, ...)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

tamirkiviti13 opened this issue · comments

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