Skip to content

Commit 77edebe

Browse files
committed
Cast form Sequence to array; Sequence.ToSwiftArray with cast
1 parent 92e85a7 commit 77edebe

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

Source/Array.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public struct Array<T>
9292
public init(repeating value: T, count: Int) {
9393
if count == 0 {
9494
list = PlatformList<T>()
95-
} else{
95+
} else{
9696
#if JAVA
9797
list = PlatformList<T>(count)
9898
for i in 0 ..< count {
@@ -181,12 +181,18 @@ public struct Array<T>
181181
public static func __implicit(_ array: T[]) -> [T] {
182182
return [T](arrayLiteral: array)
183183
}
184-
// In Coope
185-
#if !COOPER
184+
185+
#if !COOPER
186186
public static func __implicit(_ array: [T]) -> T[] {
187187
return array.nativeArray
188188
}
189-
#endif
189+
#endif
190+
191+
// Cast from sequence
192+
193+
public static func __implicit(_ sequence: ISequence<T>) -> [T] {
194+
return [T](sequence: sequence)
195+
}
190196

191197
// Cast from/to platform type
192198

@@ -253,6 +259,18 @@ public struct Array<T>
253259
return result
254260
}
255261

262+
public func +=(inout lhs: [T], rhs: [T]) {
263+
for i in rhs {
264+
lhs.append(i)
265+
}
266+
}
267+
268+
public static func += (inout lhs: Array<T>, rhs: ISequence<T>) {
269+
for i in rhs {
270+
lhs.append(i)
271+
}
272+
}
273+
256274
public static func == (lhs: [T], rhs: [T]) -> Bool {
257275
if lhs.list == rhs.list {
258276
return true

Source/Sequence_Extensions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve
3535
return result
3636
}
3737

38+
#if !COOPER
39+
public func ToSwiftArray<U>() -> [U] {
40+
var result = [U]()
41+
for i in self {
42+
result.append(i as! U)
43+
}
44+
return result
45+
}
46+
#endif
47+
3848
public var count: Int {
3949
return self.Count()
4050
}

0 commit comments

Comments
 (0)