title: Collect number of unique property values in Swift array of objects
body: <p>Say I have a simple <code>Ingredient</code> class:</p>
  
  <pre><code>class Ingredient {
      let section : String // 'Produce', 'Spices', 'Dairy', 'Grains'
  }
  </code></pre>
  
  <p>And I have a pile of <code>Ingredient</code> items:</p>
  
  <pre><code>var ingredients : [Ingredient] = ...
  </code></pre>
  
  <p>I want to collect the <strong>number of distinct sections from these ingredients</strong>.</p>
  
  <p>I can do this in Java via (relying on the auto-clumping of <code>Set</code> types):</p>
  
  <pre><code>ingredients.stream().map(Ingredient::getSection).collect(Collectors.toSet()).count()
  </code></pre>
  
  <p>Or, using the <code>distinct()</code> method:</p>
  
  <pre><code>ingredients.stream().map(Ingredient::getSection).distinct().count()
  </code></pre>
  
  <p>But <strong>I'm looking for</strong> a way to do a similar one-liner in Swift. Some of the research I've done shows people writing their own methods to collect distinct values, but I was hoping there would be a <code>distinct()</code> or <code>Set</code>-collecting method for Swift types.</p>