mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
23 lines
541 B
TypeScript
23 lines
541 B
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2020 The Pybricks Authors
|
|
|
|
/**
|
|
* Creates an iterator that counts infinitely (to Number.MAX_SAFE_INTEGER really)
|
|
* starting from 0.
|
|
*/
|
|
export function* count(): Generator<number, number, void> {
|
|
let n = 0;
|
|
while (true) {
|
|
yield n++;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a new function that counts infinitely (to Number.MAX_SAFE_INTEGER really)
|
|
* starting from 0.
|
|
*/
|
|
export function createCountFunc(): () => number {
|
|
const gen = count();
|
|
return (): number => gen.next().value;
|
|
}
|