Lấy mẫu

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

Một lựa chọn lười biếng của các phần tử, theo một thứ tự nhất định, từ một số bộ sưu tập cơ sở.

  • Tạo một thể hiện từ baseselection .

    Tuyên ngôn

    public init(base: Base, selection: Selection)
  • Tuyên ngôn

    public typealias Element = Base.Element
  • Một loại có phiên bản đại diện cho các vị trí trong self .

    Tuyên ngôn

    public typealias Index = Selection.Index
  • Vị trí của phần tử đầu tiên.

    Tuyên ngôn

    public var startIndex: Index { get }
  • Vị trí một qua phần tử cuối cùng.

    Tuyên ngôn

    public var endIndex: Index { get }
  • Trả về phần tử tại i .

    Tuyên ngôn

    public subscript(i: Index) -> Element { get }
  • Trả về vị trí sau i .

    Tuyên ngôn

    public func index(after i: Index) -> Index
  • Trả về số bước chuyển tiếp cần thiết để chuyển đổi từ start thành end .

    Kết quả âm tính cho biết end < start .

    Tuyên ngôn

    public func distance(from start: Index, to end: Index) -> Int
  • Trả về vị trí n vị trí từ i .

    Tuyên ngôn

    public func index(_ i: Index, offsetBy n: Int) -> Index
  • Trả về i offset theo distance trừ khi điều đó yêu cầu vượt qua limit , trong trường hợp đó trả về nil .

    Tuyên ngôn

    public func index(
      _ i: Index, offsetBy distance: Int, limitedBy limit: Index
    ) -> Index?
Có sẵn ở nơi `Lựa chọn`: `BidirectionalCollection`