# Implementation of Collection Versions of Zip

**URL:** <https://forums.swift.org/t/implementation-of-collection-versions-of-zip/15384>\
**Category:** Standard Library\
**Created:** [August 21, 2018, 1:34am UTC](https://forums.swift.org/t/implementation-of-collection-versions-of-zip/15384 "2018-08-21T01:34:15Z")\
**Posts on this page:** 1\
**Showing post:** 36

<div class="post-metadata">

**Author:** ![dennisvennink](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dennisvennink/32/3637_2.png) [@dennisvennink](https://forums.swift.org/u/dennisvennink)\
**Post date:** [October 27, 2018, 6:51pm UTC](https://forums.swift.org/t/implementation-of-collection-versions-of-zip/15384/36 "2018-10-27T18:51:28Z")

</div>

I'm looking into conforming `Zip2Collection` to both `ExpressibleByArrayLiteral` and `ExpressibleByDictionaryLiteral`:

```swift
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)
    }
  }
}

```

```swift
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. 👍

---

_[View the full topic](https://forums.swift.org/t/implementation-of-collection-versions-of-zip/15384)._
