InfiniteSequence.swift 589 B

1234567891011121314151617181920212223
  1. //
  2. // InfiniteSequence.swift
  3. // Platform
  4. //
  5. // Created by Krunoslav Zaher on 6/13/15.
  6. // Copyright © 2015 Krunoslav Zaher. All rights reserved.
  7. //
  8. /// Sequence that repeats `repeatedValue` infinite number of times.
  9. struct InfiniteSequence<Element> : Sequence {
  10. typealias Iterator = AnyIterator<Element>
  11. private let repeatedValue: Element
  12. init(repeatedValue: Element) {
  13. self.repeatedValue = repeatedValue
  14. }
  15. func makeIterator() -> Iterator {
  16. let repeatedValue = self.repeatedValue
  17. return AnyIterator { repeatedValue }
  18. }
  19. }