"So a generator is simply something that can give you the next element of some sequence of elements."
Is this a common usage of the word "generator"?
At least in JavaScript and Python you'd call that an "iterator", and a "generator" is a special type of function that acts as an iterator, using the "yield" keyword.
8 comments
[ 3.1 ms ] story [ 30.5 ms ] threadhttp://www.h4labs.com/dev/ios/swift.html
And I just posted it to HN here:
https://news.ycombinator.com/item?id=8815739
https://github.com/melling/SwiftResource
The data is here:
https://github.com/melling/SwiftResource/blob/master/swift_u...
For this to work, I probably need scripts to prevent duplicates, etc.
Is this a common usage of the word "generator"?
At least in JavaScript and Python you'd call that an "iterator", and a "generator" is a special type of function that acts as an iterator, using the "yield" keyword.
// Fibonacci sequence
let fib = SequenceOf { () -> GeneratorOf<Int> in
}// Print Fibonacci numbers <= 1000
for e in fib {
}println()
$ xcrun swift fib_test.swift
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
See http://www.oki-osk.jp/esc/swift/linq.html