Created
September 5, 2017 15:23
-
-
Save dclelland/0afa6117a43c5c468a5f281eb0dda26e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func zip<A>(_ arrays: [[A]]) -> ZipArrayCollection<A> { | |
return ZipArrayCollection(arrays) | |
} | |
public struct ZipArrayCollection<A>: Collection { | |
private let arrays: [[A]] | |
public let startIndex: Int | |
public let endIndex: Int | |
public init(_ arrays: [[A]]) { | |
self.arrays = arrays | |
self.startIndex = arrays.first?.startIndex ?? 0 | |
self.endIndex = arrays.first?.endIndex ?? 0 | |
} | |
public subscript(position: Int) -> [A] { | |
return arrays.map { array in | |
return array[position] | |
} | |
} | |
public func index(after index: Int) -> Int { | |
return index + 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment