Files
swift-mirror/stdlib/core/Repeat.swift
Dave Abrahams 6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00

41 lines
1.1 KiB
Swift

//===--- Repeat.swift - A CollectionType that repeats a value N times -----===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
public struct Repeat<T> : CollectionType {
public typealias Index = Int
public init(count: Int, repeatedValue: T) {
self.count = count
self.repeatedValue = repeatedValue
}
public var startIndex: Index {
return 0
}
public var endIndex: Index {
return count
}
public func generate() -> IndexingGenerator<Repeat> {
return IndexingGenerator(self)
}
public subscript(i: Int) -> T {
_precondition(i < count, "Index out of range")
return repeatedValue
}
public var count: Int
public let repeatedValue: T
}