Last active
March 19, 2019 21:48
-
-
Save michaeleisel/2439fe647b798dbdd75c5ba85c09e574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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