RangeReplaceableCollection

extension RangeReplaceableCollection
extension RangeReplaceableCollection where Self: BidirectionalCollection
  • Replace element at given index with the given element.

    Declaration

    Swift

    @discardableResult
    public mutating func replaceElement(at index: Index, with element: Element) -> Element
  • Immutable version of replaceElement(at:with:)

    Declaration

    Swift

    public func replacingElement(at index: Index, with element: Element) -> Self
  • Replace first element in Array with a new element.

    Declaration

    Swift

    @discardableResult
    public mutating func replaceFirst(with element: Element) -> Element
  • Declaration

    Swift

    public func inserting(_ element: Element, at index: Index) -> Self

    Return Value

    A new Array with the given element inserted at the given index, if possible.

Available where Self: BidirectionalCollection

  • Replace the last element in Self with the given element.

    Declaration

    Swift

    @discardableResult
    public mutating func replaceLast(with element: Element) -> Element