Contents

replacing(_:with:maxReplacements:)

Returns a new collection in which all occurrences of a target sequence are replaced by another collection.

Declaration

func replacing<C, Replacement>(_ other: C, with replacement: Replacement, maxReplacements: Int = .max) -> Self where C : Collection, Replacement : Collection, Self.Element == C.Element, C.Element == Replacement.Element

Parameters

  • other:

    The sequence to replace.

  • replacement:

    The new elements to add to the collection.

  • maxReplacements:

    A number specifying how many occurrences of other to replace. Default is Int.max.

Return Value

A new collection in which all occurrences of other in subrange of the collection are replaced by replacement.