title: iOS Swift - Reduce function
body: <p>I have a piece of code in SWIFT that I don't understand: </p>
  
  <pre><code>var peers: [String:NSSet] = [:]
  for s in squares {
    var ps = reduce(units[s]!, NSMutableSet()) { set, u in
      set.addObjectsFromArray(u)
      return set
    }
    ps.removeObject(s)
    peers[s] = ps
  }
  </code></pre>
  
  <p><code>squares</code> is an array of String. </p>
  
  <p>So far I have realized that <code>peers</code> probably is a key/value data structure with keys of String and values of NSSet. NSSet is similar to Array but it cannot accept duplicate items. The main part that I don't understand is actually the <code>reduce</code> function. Any explanation or instructive article/webpage is appreciated. </p>