by srparish · 7y ago · 0 comments
Rust and Java both have good APIs for this kind of work. Take a look at their approaches.
(And I almost did a spittake thinking about C++ being more productive than Go.)
Out of curiosity, in which language(s) were those written in?
Reduce is quite elegant for certain kinds of problems. But in most practical settings, knowing when to reach for reduce vs something else is hard to know, and everyone has different opinions on it. Personally, I like to sidestep those kinds of decisions/discussions whenever I can, because it just gets in the way of actually delivering stuff.
TypeScript/JavaScript:
const itemIDs = items.map((item) => item.ID)
Go: itemIDs := make([]uint64, 0, len(items))
for _, item := range items {
itemIDs = append(itemIDs, item.ID)
}