@@ -19,7 +19,7 @@ extension Array {
19
19
}
20
20
21
21
/// EZSE: Checks if array contains at least 1 instance of the given object type
22
- public func containsInstanceOf< T> ( object: T ) -> Bool {
22
+ public func containsInstanceOf< T> ( _ object: T ) -> Bool {
23
23
for item in self {
24
24
if item. dynamicType == object. dynamicType {
25
25
return true
@@ -29,7 +29,7 @@ extension Array {
29
29
}
30
30
31
31
/// EZSE: Checks if test returns true for all the elements in self
32
- public func testAll( test: ( Element ) -> Bool ) -> Bool {
32
+ public func testAll( _ test: ( Element ) -> Bool ) -> Bool {
33
33
for item in self {
34
34
if !test( item) {
35
35
return false
@@ -39,7 +39,7 @@ extension Array {
39
39
}
40
40
41
41
/// EZSE: Checks if all elements in the array are true of false
42
- public func testIfAllIs( condition: Bool ) -> Bool {
42
+ public func testIfAllIs( _ condition: Bool ) -> Bool {
43
43
for item in self {
44
44
guard let item = item as? Bool else { return false }
45
45
@@ -51,30 +51,30 @@ extension Array {
51
51
}
52
52
53
53
/// EZSE: Gets the object at the specified index, if it exists.
54
- public func get( index: Int ) -> Element ? {
54
+ public func get( _ index: Int ) -> Element ? {
55
55
return index >= 0 && index < count ? self [ index] : nil
56
56
}
57
57
58
58
/// EZSE: Reverse the given index. i.g.: reverseIndex(2) would be 2 to the last
59
- public func reverseIndex( index: Int ) -> Int {
59
+ public func reverseIndex( _ index: Int ) -> Int {
60
60
return Swift . max ( self . count - 1 - index, 0 )
61
61
}
62
62
63
63
/// EZSE: Returns an array with the given number as the max number of elements.
64
- public func takeMax( n: Int ) -> Array {
64
+ public func takeMax( _ n: Int ) -> Array {
65
65
return Array ( self [ 0 ..< Swift . max ( 0 , Swift . min ( n, count) ) ] )
66
66
}
67
67
68
68
/// EZSE: Iterates on each element of the array.
69
- public func each( call: ( Element ) -> ( ) ) {
69
+ public func each( _ call: ( Element ) -> ( ) ) {
70
70
for item in self {
71
71
call ( item)
72
72
}
73
73
}
74
74
75
75
/// EZSE: Iterates on each element of the array with its index.
76
- public func each( call: ( Int , Element ) -> ( ) ) {
77
- for (index, item) in self . enumerate ( ) {
76
+ public func each( _ call: ( Int , Element ) -> ( ) ) {
77
+ for (index, item) in self . enumerated ( ) {
78
78
call ( index, item)
79
79
}
80
80
}
@@ -92,8 +92,8 @@ extension Array {
92
92
}
93
93
94
94
/// EZSE: Prepends an object to the array.
95
- public mutating func insertAsFirst( newElement: Element ) {
96
- insert ( newElement, atIndex : 0 )
95
+ public mutating func insertAsFirst( _ newElement: Element ) {
96
+ insert ( newElement, at : 0 )
97
97
}
98
98
99
99
/// EZSE: Shuffles the array in-place using the Fisher-Yates-Durstenfeld algorithm.
@@ -110,7 +110,7 @@ extension Array {
110
110
extension Array where Element: Equatable {
111
111
112
112
/// EZSE: Returns the indexes of the object
113
- public func indexesOf( object: Element ) -> [ Int ] {
113
+ public func indexesOf( _ object: Element ) -> [ Int ] {
114
114
var indexes = [ Int] ( )
115
115
for index in 0 ..< self . count {
116
116
if self [ index] == object {
@@ -121,17 +121,17 @@ extension Array where Element: Equatable {
121
121
}
122
122
123
123
/// EZSE: Returns the last index of the object
124
- public func lastIndexOf( object: Element ) -> Int ? {
124
+ public func lastIndexOf( _ object: Element ) -> Int ? {
125
125
return indexesOf ( object) . last
126
126
}
127
127
128
128
/// EZSE: Checks if self contains a list of items.
129
- public func contains( items: Element ... ) -> Bool {
130
- return items. testAll { self . indexOf ( $0) >= 0 }
129
+ public func contains( _ items: Element ... ) -> Bool {
130
+ return items. testAll { self . index ( of : $0) >= 0 }
131
131
}
132
132
133
133
/// EZSE: Difference of self and the input arrays.
134
- public func difference( values: [ Element ] ... ) -> [ Element ] {
134
+ public func difference( _ values: [ Element ] ... ) -> [ Element ] {
135
135
var result = [ Element] ( )
136
136
elements: for element in self {
137
137
for value in values {
@@ -148,11 +148,11 @@ extension Array where Element: Equatable {
148
148
}
149
149
150
150
/// EZSE: Intersection of self and the input arrays.
151
- public func intersection( values: [ Element ] ... ) -> Array {
151
+ public func intersection( _ values: [ Element ] ... ) -> Array {
152
152
var result = self
153
153
var intersection = Array ( )
154
154
155
- for (i, value) in values. enumerate ( ) {
155
+ for (i, value) in values. enumerated ( ) {
156
156
// the intersection is computed by intersecting a couple per loop:
157
157
// self n values[0], (self n values[0]) n values[1], ...
158
158
if i > 0 {
@@ -172,7 +172,7 @@ extension Array where Element: Equatable {
172
172
}
173
173
174
174
/// EZSE: Union of self and the input arrays.
175
- public func union( values: [ Element ] ... ) -> Array {
175
+ public func union( _ values: [ Element ] ... ) -> Array {
176
176
var result = self
177
177
for array in values {
178
178
for value in array {
@@ -185,21 +185,21 @@ extension Array where Element: Equatable {
185
185
}
186
186
187
187
/// EZSE: Removes the first given object
188
- public mutating func removeObject( object: Element ) {
189
- if let index = self . indexOf ( object) {
190
- self . removeAtIndex ( index)
188
+ public mutating func removeObject( _ object: Element ) {
189
+ if let index = self . index ( of : object) {
190
+ self . remove ( at : index)
191
191
}
192
192
}
193
193
194
194
/// EZSE: Removes all occurrences of the given object
195
- public mutating func removeObjects( object: Element ) {
196
- for i in self . indexesOf ( object) . reverse ( ) {
197
- self . removeAtIndex ( i)
195
+ public mutating func removeObjects( _ object: Element ) {
196
+ for i in self . indexesOf ( object) . reversed ( ) {
197
+ self . remove ( at : i)
198
198
}
199
199
}
200
200
201
201
/// EZSE: Checks if the main array contains the parameter array
202
- public func containsArray( lookFor: [ Element ] ) -> Bool {
202
+ public func containsArray( _ lookFor: [ Element ] ) -> Bool {
203
203
for item in lookFor {
204
204
if self . contains ( item) == false {
205
205
return false
@@ -211,9 +211,9 @@ extension Array where Element: Equatable {
211
211
212
212
public func == < T: Equatable > ( lhs: [ T ] ? , rhs: [ T ] ? ) -> Bool {
213
213
switch ( lhs, rhs) {
214
- case ( . Some ( let lhs) , . Some ( let rhs) ) :
214
+ case ( . some ( let lhs) , . some ( let rhs) ) :
215
215
return lhs == rhs
216
- case ( . None , . None ) :
216
+ case ( . none , . none ) :
217
217
return true
218
218
default :
219
219
return false
0 commit comments