4 ms·
Instead of map/filter: // using some fake filter/map/lambda syntax names := machines.filter(strings.HasPrefix(m.tag, "ec2")).map(|m| = m.name) why not
by NateDad 12y ago
Instead of map/filter:
// using some fake filter/map/lambda syntax
names := machines.filter(strings.HasPrefix(m.tag, "ec2")).map(|m| = m.name)
why not just write
names := []string{}
for _, m := range machines {
if strings.HasPrefix(m.tag, "ec2") {
names = append(names, m.name)
}
}
What happens when you read that first implementation? Don't you read it as "for each machine, if its tag has the prefix "ec2", then append its name to the list that is returned? Isn't that the exact same thing you'd read the second one as? Except that the second one requires no special knowledge other than loops and if statements.