Collection

extension Collection
extension Collection where Self == Self.SubSequence
  • Returns a partition of self with at most maxCount chunks.

    Declaration

    Swift

    public func chunked(inMax maxCount: Int) -> Chunks<Self>
  • Accesses the unique element of the collection.

    This property is nil unless self.count == 1.

    Declaration

    Swift

    public var uniqueElement: Element? { get }
  • The first element of self and its suffix after its first index or nil if self is empty.

    Declaration

    Swift

    public var headAndTail: (head: Element, tail: SubSequence)? { get }
  • Returns the minimal elements of self using compare to 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 of self.

    Declaration

    Swift

    public func minimalElements(
      by compare: (Element, Element) -> StrictPartialOrdering
    ) -> [Element]

Available where Self == Self.SubSequence

  • Removes prefix from the beginning and returns true, or returns false if self has 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 shouldBeKept or self is 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