Guest User

Untitled

a guest
Feb 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /// Returns a subsequence, up to the specified maximum length, containing
  2. /// the initial elements of the collection.
  3. ///
  4. /// If the maximum length exceeds the number of elements in the collection,
  5. /// the result contains all the elements in the collection.
  6. ///
  7. /// ...
  8. /// - Parameter maxLength: The maximum number of elements to return.
  9. /// `maxLength` must be greater than or equal to zero.
  10. /// - Returns: A subsequence starting at the beginning of this collection
  11. /// with at most `maxLength` elements.
  12. @_inlineable
  13. public func prefix(_ maxLength: Int) -> SubSequence {
  14. _precondition(
  15. maxLength >= 0,
  16. "Can't take a prefix of negative length from a collection")
  17. let end = index(startIndex,
  18. offsetBy: maxLength, limitedBy: endIndex) ?? endIndex
  19. return self[startIndex..<end]
  20. }
  21.  
  22. extension String : StringProtocol, RangeReplaceableCollection {
  23. /// A type that represents the number of steps between two `String.Index`
  24. /// values, where one value is reachable from the other.
  25. ///
  26. /// In Swift, *reachability* refers to the ability to produce one value from
  27. /// the other through zero or more applications of `index(after:)`.
  28. public typealias IndexDistance = Int
  29.  
  30. public typealias SubSequence = Substring
  31.  
  32. // ...
  33. }
  34.  
  35. func prefix(_ maxLength: Int) -> Substring
Add Comment
Please, Sign In to add comment