I'm looking into conforming Zip2Collection
to both ExpressibleByArrayLiteral
and ExpressibleByDictionaryLiteral
:
extension Zip2Collection: ExpressibleByArrayLiteral where
Collection1: RangeReplaceableCollection,
Collection2: RangeReplaceableCollection {
public typealias ArrayLiteralElement = Element
public init (arrayLiteral: Element...) {
self.init()
let arrayLiteralCount = arrayLiteral.count
_collection1.reserveCapacity(arrayLiteralCount)
_collection2.reserveCapacity(arrayLiteralCount)
for (element1, element2) in arrayLiteral {
_collection1.append(element1)
_collection2.append(element2)
}
}
}
extension Zip2Collection: ExpressibleByDictionaryLiteral where
Collection1: RangeReplaceableCollection,
Collection2: RangeReplaceableCollection {
public typealias Key = Collection1.Element
public typealias Value = Collection2.Element
public init (dictionaryLiteral elements: Element...) {
self.init()
let elementsCount = elements.count
_collection1.reserveCapacity(elementsCount)
_collection2.reserveCapacity(elementsCount)
for (element1, element2) in elements {
_collection1.append(element1)
_collection2.append(element2)
}
}
}
If anybody sees any room for improvement here, let me know.