Last active
August 29, 2015 14:26
-
-
Save oisdk/bcf6fb8e9eee4cb79cdc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 final class AnyGen<Element> : GeneratorType { | |
private let nextFunc: () -> Element? | |
public final func next() -> Element? { return nextFunc() } | |
public init<G : GeneratorType where G.Element == Element>(var _ base: G) { | |
nextFunc = {base.next()} | |
} | |
} | |
public struct AnySeq<Element> : SequenceType { | |
private let genFunc: () -> AnyGen<Element> | |
public func generate() -> AnyGen<Element> { return genFunc() } | |
public init<S : SequenceType where S.Generator.Element == Element>(_ base: S) { | |
genFunc = {AnyGen(base.generate())} | |
} | |
} | |
// Or, using AnyGenerator: | |
public struct AnySeqG<Element> : SequenceType { | |
private let genFunc: () -> AnyGenerator<Element> | |
public func generate() -> AnyGenerator<Element> { return genFunc() } | |
public init<S : SequenceType where S.Generator.Element == Element>(_ base: S) { | |
genFunc = {anyGenerator(base.generate())} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment