Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Returns a subsequence, up to the specified maximum length, containing
- /// the initial elements of the collection.
- ///
- /// If the maximum length exceeds the number of elements in the collection,
- /// the result contains all the elements in the collection.
- ///
- /// ...
- /// - Parameter maxLength: The maximum number of elements to return.
- /// `maxLength` must be greater than or equal to zero.
- /// - Returns: A subsequence starting at the beginning of this collection
- /// with at most `maxLength` elements.
- @_inlineable
- public func prefix(_ maxLength: Int) -> SubSequence {
- _precondition(
- maxLength >= 0,
- "Can't take a prefix of negative length from a collection")
- let end = index(startIndex,
- offsetBy: maxLength, limitedBy: endIndex) ?? endIndex
- return self[startIndex..<end]
- }
- extension String : StringProtocol, RangeReplaceableCollection {
- /// A type that represents the number of steps between two `String.Index`
- /// values, where one value is reachable from the other.
- ///
- /// In Swift, *reachability* refers to the ability to produce one value from
- /// the other through zero or more applications of `index(after:)`.
- public typealias IndexDistance = Int
- public typealias SubSequence = Substring
- // ...
- }
- func prefix(_ maxLength: Int) -> Substring
Add Comment
Please, Sign In to add comment