Skip to content

Instantly share code, notes, and snippets.

@Qata
Created May 30, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qata/8cada0d09b667748a0c8e5ed61e45a04 to your computer and use it in GitHub Desktop.
Save Qata/8cada0d09b667748a0c8e5ed61e45a04 to your computer and use it in GitHub Desktop.
public extension LazySequence {
/// Create an infinitely repeating sequence of values identical to `value`.
///
/// let names = ["Jane", "Jack", "Gwynne", "Micky"]
/// let hellos = LazySequence(repeating: "Hello")
/// let g = zip(hellos, names).map { "\($0), \($1)" }
/// g == ["Hello, Jane", "Hello, Jack", "Hello, Gwynne", "Hello, Micky"]
///
/// - Parameter repeating: `repeating` takes the element to be repeated.
/// - Returns: An infinite lazy sequence of `value`.
init<T>(repeating value: T) where Base == AnyIterator<T> {
self = AnyIterator { value }.lazy
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment