ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

Sampling

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

A lazy selection of elements, in a given order, from some base collection.

  • Creates an instance from base and selection.

    Declaration

    public init(base: Base, selection: Selection)
  • Declaration

    public typealias Element = Base.Element
  • A type whose instances represent positions in self.

    Declaration

    public typealias Index = Selection.Index
  • The position of the first element.

    Declaration

    public var startIndex: Index { get }
  • The position one past the last element.

    Declaration

    public var endIndex: Index { get }
  • Returns the element at i.

    Declaration

    public subscript(i: Index) -> Element { get }
  • Returns the position after i.

    Declaration

    public func index(after i: Index) -> Index
  • Returns the number of forward steps required to convert start into end.

    A negative result indicates that end < start.

    Declaration

    public func distance(from start: Index, to end: Index) -> Int
  • Returns the position n places from i.

    Declaration

    public func index(_ i: Index, offsetBy n: Int) -> Index
  • Returns i offset by distance unless that requires passing limit, in which case nil is returned.

    Declaration

    public func index(
      _ i: Index, offsetBy distance: Int, limitedBy limit: Index
    ) -> Index?