title: Swift 4 Array Find or First
body: <p>I'm trying to perform a filter on an array of structs whereby if the element exists return the element, otherwise return the first element in the array.  At the moment I have a <code>func</code> to do this, was wondering if there was a more efficient way.  Predicate or Array extension?</p>
  
  <p>For example, if this is my array of structures and method:</p>
  
  <pre><code>struct Person { 
     let name: String
     let age: Int
   }
  
   let items = [Person(name: "Fred", age: 12), 
                Person(name: "Bill", age: 14), 
                Person(name: "Jane", age: 15), 
                Person(name: "Mary", age: 12)]
  
   // Find the person based on name, if no match, return first item
   func filterOrFirst(with name: String? = "") -&gt; Person?
   {
      if (items.contains(where: {$0.name == name}))
      {
          return items.first(where: {$0.name == name})
      }
      return items.first
   }
  
   print(filterOrFirst(with: "Bill"))   // prints Bill 
   print(filterOrFirst())               // prints Fred
  </code></pre>