title: How to follow DRY principle in Go in function?
body: <p>I have this function to find the first Account that satisfies a predicate.</p>
  
  <pre><code>func findAccount(accounts []Account, f func(Account) bool) (*Account, error) {
      for _, account := range accounts {
          if f(account) {
              return &amp;account, nil
          }
      }
      return nil, ErrNoSuchAccount
  }
  </code></pre>
  
  <p>and another function to find the first Team that satisfies a predicate.</p>
  
  <pre><code>func findTeam(teams []Team, f func(Team) bool) (*Team, error) {
      for _, team := range teams {
          if f(team) {
              return &amp;team, nil
          }
      }
      return nil, ErrNoSuchTeam
  }
  </code></pre>
  
  <p>To DRY, I wonder if they can be combined as most lines of the routines are identical.</p>