דגימות

public struct Sampling<Base: Collection, Selection: Collection>
where Selection.Element == Base.Index
extension Sampling: SamplingProtocol
extension Sampling: Collection
extension Sampling: BidirectionalCollection
  where Selection: BidirectionalCollection
extension Sampling: RandomAccessCollection
  where Selection: RandomAccessCollection

מבחר עצלן של אלמנטים, בסדר נתון, מאוסף בסיס כלשהו.

  • יוצר מופע base selection .

    הַצהָרָה

    public init(base: Base, selection: Selection)
  • הַצהָרָה

    public typealias Element = Base.Element
  • טיפוס שהמופעים שלו מייצגים עמדות self .

    הַצהָרָה

    public typealias Index = Selection.Index
  • המיקום של האלמנט הראשון.

    הַצהָרָה

    public var startIndex: Index { get }
  • המיקום אחד מעבר לאלמנט האחרון.

    הַצהָרָה

    public var endIndex: Index { get }
  • מחזירה את הרכיב ב- i .

    הַצהָרָה

    public subscript(i: Index) -> Element { get }
  • מחזירה את המיקום אחרי i .

    הַצהָרָה

    public func index(after i: Index) -> Index
  • מחזירה את מספר הצעדים קדימה הנדרשים להמרת start end .

    תוצאה שלילית מציינת end < start .

    הַצהָרָה

    public func distance(from start: Index, to end: Index) -> Int
  • מחזירה את המיקום n מקומות מ- i .

    הַצהָרָה

    public func index(_ i: Index, offsetBy n: Int) -> Index
  • החזרות i מקוזזות לפי distance , אלא אם כן הדבר מצריך limit מעבר , ובמקרה זה nil מוחזר.

    הַצהָרָה

    public func index(
      _ i: Index, offsetBy distance: Int, limitedBy limit: Index
    ) -> Index?
זמין כאשר 'בחירה': 'BidirectionalCollection'