Collection
extension Collection
extension Collection where Self == Self.SubSequence
-
Returns a partition of self with at most
maxCountchunks.Declaration
Swift
public func chunked(inMax maxCount: Int) -> Chunks<Self> -
Accesses the unique element of the collection.
This property is
nilunlessself.count == 1.Declaration
Swift
public var uniqueElement: Element? { get } -
The first element of
selfand its suffix after its first index ornilifselfis empty.Declaration
Swift
public var headAndTail: (head: Element, tail: SubSequence)? { get } -
Returns the minimal elements of
selfusingcompareto order them.A minimal element of a set S with a strict partial order R is an element not smaller than any other element in S. If S is a finite set and R is a strict total order, the notions of minimal element and minimum coincide.
Complexity
O(n^2) where n is the length ofself.Declaration
Swift
public func minimalElements( by compare: (Element, Element) -> StrictPartialOrdering ) -> [Element]
-
Removes
prefixfrom the beginning and returnstrue, or returnsfalseifselfhas no such prefix.Declaration
Swift
public mutating func removeLeading<P: Collection>(_ prefix: P) -> Bool where P.Element == Element, Element: Equatable -
Removes elements from the beginning until the first element satisfies
shouldBeKeptorselfis empty, returning the removed subsequence.Declaration
Swift
@discardableResult public mutating func removeFirstUntil(it shouldBeKept: (Element) -> Bool) -> Self -
Removes elements from the beginning that satisfy
shouldBeRemoved, returning the removed subsequence.Declaration
Swift
@discardableResult public mutating func removeFirstWhile(it shouldBeRemoved: (Element) -> Bool) -> Self
View on GitHub