InfiniteSequence.swift 611 B

1234567891011121314151617181920212223242526
  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<E> : Sequence {
  10. typealias Element = E
  11. typealias Iterator = AnyIterator<E>
  12. private let _repeatedValue: E
  13. init(repeatedValue: E) {
  14. _repeatedValue = repeatedValue
  15. }
  16. func makeIterator() -> Iterator {
  17. let repeatedValue = _repeatedValue
  18. return AnyIterator {
  19. return repeatedValue
  20. }
  21. }
  22. }