interspersed(with:)

Returns a sequence containing elements of this sequence with the given separator inserted in between each element.

Intersperse.swift:634
func interspersed(with separator: Element) -> InterspersedSequence<Self>

Parameters

separator

Value to insert in between each of this sequence’s elements.

Returns

The interspersed sequence of elements.

Any value of the sequence’s element type can be used as the separator.

for value in [1,2,3].interspersed(with: 0) {
    print(value)
}
// 1
// 0
// 2
// 0
// 3

The following shows a String being interspersed with a Character:

let result = "ABCDE".interspersed(with: "-")
print(String(result))
// "A-B-C-D-E"