A collection containing a single element.

@frozen struct CollectionOfOne<Element>


You can use a CollectionOfOne instance when you need to efficiently represent a single value as a collection. For example, you can add a single element to an array by using a CollectionOfOne instance with the concatenation operator (+):

let a = [1, 2, 3, 4]
let toAdd = 100
let b = a + CollectionOfOne(toAdd)
// b == [1, 2, 3, 4, 100]



  • typealias Index

    A type that represents a position in the collection.

  • typealias Indices

    A type that represents the indices that are valid for subscripting the collection, in ascending order.

  • typealias SubSequence

    A collection representing a contiguous subrange of this collection’s elements. The subsequence shares indices with the original collection.


  • init(Element)

    Creates an instance containing just the given element.

Instance Subscripts

Instance Properties

Instance Methods


  • struct Iterator

    An iterator that produces one or zero instances of an element.

Conforms To

Removed Members

Instance Subscripts

Instance Methods