RangeReplaceableCollection
protocol RangeReplaceableCollection : Collection where Self.SubSequence : RangeReplaceableCollection
-
Mechanica
Appends a new
element
.Declaration
Swift
@discardableResult public func appending(_ element: Element) -> Self
-
Mechanica
Removes the first element that matches the given
condition
.Declaration
Swift
@discardableResult public mutating func removeFirst(where condition: (Element) -> Bool) -> Element?
Parameters
condition
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
-
Mechanica
Removes the first element that matches the given
condition
and returns a tuple with anew
collection and the removed element.Declaration
Swift
public func removingFirst(where condition: (Element) -> Bool) -> (Self, Element?)
Parameters
condition
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
Return Value
A tuple with a
new
collection and the removed element. -
Mechanica
Removes the last element that matches the given
condition
.Declaration
Swift
@discardableResult public mutating func removeLast(where condition: (Element) -> Bool) -> Element?
Parameters
condition
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
-
Mechanica
Removes the last element that matches the given
condition
and returns a tuple with anew
collection and the removed element.Declaration
Swift
public func removingLast(where condition: (Element) -> Bool) -> (Self, Element?)
Parameters
condition
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
Return Value
A tuple with a
new
collection and the removed element.
-
Mechanica
Removes all the elements that matches the given
condition
and returns all the removed element (if any).Note
usefilter
if you don’t need the removed element.Declaration
Swift
@discardableResult public mutating func remove(where condition: (Element) -> Bool) -> [Element]
Parameters
condition
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
-
Mechanica
Removes all the elements that matches the given
condition
and returns a tuple with anew
collection and the removed elements.Note
usefilter
if you don’t need the removed element.Declaration
Swift
public func removing(where condition: (Element) -> Bool) -> (Self, [Element])
Parameters
condition
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
Return Value
A tuple with a
new
collection and the removed elements.
-
Mechanica Removes the first specified element from the collection (if exists).
Declaration
Swift
@discardableResult public mutating func removeFirstOccurrence(of element: Element) -> Element?
Parameters
element
The element to remove the last occurrence.
Return Value
The element removed (if any).
-
Mechanica
Removes the last specified element from the array (if exists).
Declaration
Swift
@discardableResult public mutating func removeLastOccurrence(of element: Element) -> Element?
Parameters
element
The element to remove the collection occurrence.
Return Value
The element removed (if any).