by eweise · 4y ago · 0 comments
addresses := persons.map(func(p Person) Address {p.address})
Actually what I really want is
addresses := persons.map(p => p.address)
But I understand Go doesn't allow that level of readability.
Say you have a list of classes and want to pull out certain fields. With immutability as default and easy map functions many people write something like this:
a = my list.map(e => e.foo)
b = mylist.map(e => e.bar)
This may or may not matter performance wise but I think Go has a strong culture of of making something like this easy vs writing a for loop that does everything in one go.