I have a piece of code in SWIFT that I don't understand:
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
}
squares is an array of String.
So far I have realized that peers 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 reduce function. Any explanation or instructive article/webpage is appreciated.