I have this function to find the first Account that satisfies a predicate.
func findAccount(accounts []Account, f func(Account) bool) (*Account, error) {
for _, account := range accounts {
if f(account) {
return &account, nil
}
}
return nil, ErrNoSuchAccount
}
and another function to find the first Team that satisfies a predicate.
func findTeam(teams []Team, f func(Team) bool) (*Team, error) {
for _, team := range teams {
if f(team) {
return &team, nil
}
}
return nil, ErrNoSuchTeam
}
To DRY, I wonder if they can be combined as most lines of the routines are identical.