The simplest, stupidest, handiest helper function I've made in a while.
Odd/Even CSS classes? A list of proxy IPs? Whatevs.
The simplest, stupidest, handiest helper function I've made in a while.
Odd/Even CSS classes? A list of proxy IPs? Whatevs.
@mb21 hah, that was actually my next to-do :D
@eaton Sorry, couldn’t help myself to write it as a generator function (which return iterators with a .next method):
function * makeRotator (items) {
let i = 0
while (true) {
yield items[i % items.length]
i++
}
}
but yeah, not sure it’s worth the complexity…
@eaton How did you get assigning fields to the r function to type-check?! And why not just use local variables for index and items?
@mb21 at least in TS 5.4, that all typechecks correctly — I *believe* the key is that the freshly created function being returned gets its own explicit typing based on what you pass in; you’re not relying on the typing of the makeRotator func, but I’d have to dig in a bit more.
@mb21 unrelated to the generator-ness, I do like using i % length — hadn’t occurred to me to use that, and as a side effect, there’s an internal record of how many times the func’s been called!
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.