Skip to content

Instantly share code, notes, and snippets.

@michaeleisel
Last active March 19, 2019 21:48
Show Gist options
  • Save michaeleisel/2439fe647b798dbdd75c5ba85c09e574 to your computer and use it in GitHub Desktop.
Save michaeleisel/2439fe647b798dbdd75c5ba85c09e574 to your computer and use it in GitHub Desktop.
public extension Sequence {
public func mySequence() -> AnySequence<Element> {
return AnySequence { () -> AnyIterator<Element> in
var iterator = self.makeIterator()
return AnyIterator {
return iterator.next()
}
}
}
}
func f() {
let b = [1, 2, 3, 4]
let s = b.mySequence().drop { $0 < 3 }
let i1 = Array(s) // [3, 4]
let i2 = Array(s) // [3]
// why does i1 not equal i2? and when you just do `let s = b.mySequence()` or `b.mySequence().lazy` without the drop, it works fine
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment