Created
December 17, 2015 13:14
-
-
Save ezura/b282f431c11c337a088c 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
struct SampleStruct {} | |
extension SampleStruct : SequenceType { | |
typealias Generator = SampleGenerator | |
func generate() -> Generator { | |
return Generator() | |
} | |
} | |
struct SampleGenerator : GeneratorType { | |
typealias Element = Int | |
var index = 0 | |
mutating func next() -> Element? { | |
index++ | |
if (index > 10) { return nil } | |
return Int(arc4random()) | |
} | |
} | |
let sampleStruct = SampleStruct() | |
sampleStruct.map { $0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment