@@ -58,11 +58,7 @@ public struct SortedSet<T: Comparable>: Probable, Collection, Equatable, CustomS
5858 :name: asArray
5959 */
6060 public var asArray : [ Element ] {
61- var a = [ Element] ( )
62- for x in self {
63- a. append ( x)
64- }
65- return a
61+ return map { $0 }
6662 }
6763
6864 /**
@@ -72,15 +68,7 @@ public struct SortedSet<T: Comparable>: Probable, Collection, Equatable, CustomS
7268 - returns: String
7369 */
7470 public var description : String {
75- var output = " [ "
76- let l = count - 1
77- for i in 0 ..< count {
78- output += " \( self [ i] ) "
79- if i != l {
80- output += " , "
81- }
82- }
83- return output + " ] "
71+ return " [ " + map { " \( $0) " } . joined ( separator: " , " ) + " ] "
8472 }
8573
8674 /**
@@ -105,15 +93,6 @@ public struct SortedSet<T: Comparable>: Probable, Collection, Equatable, CustomS
10593 return tree. last? . value
10694 }
10795
108- /**
109- :name: isEmpty
110- :description: A boolean of whether the RedBlackTree is empty.
111- - returns: Bool
112- */
113- public var isEmpty : Bool {
114- return 0 == count
115- }
116-
11796 /**
11897 :name: startIndex
11998 :description: Conforms to the Collection Protocol.
@@ -158,15 +137,8 @@ public struct SortedSet<T: Comparable>: Probable, Collection, Equatable, CustomS
158137 }
159138
160139 public func makeIterator( ) -> SortedSet . Iterator {
161- var index = startIndex
162- return AnyIterator {
163- if index < self . endIndex {
164- let i = index
165- index += 1
166- return self [ i]
167- }
168- return nil
169- }
140+ var i = indices. makeIterator ( )
141+ return AnyIterator { i. next ( ) . map { self [ $0] } }
170142 }
171143
172144 /**
@@ -283,7 +255,7 @@ public struct SortedSet<T: Comparable>: Probable, Collection, Equatable, CustomS
283255 */
284256 mutating public func insert( _ elements: [ Element ] ) {
285257 for x in elements {
286- tree. insert ( value: x, for: x)
258+ tree. insert ( value: x, for: x)
287259 }
288260 count = tree. count
289261 }
0 commit comments