@thi.ng/transducers
Version:
Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations
17 lines (16 loc) • 485 B
JavaScript
import { isIterable } from "@thi.ng/checks/is-iterable";
import { now, timeDiff } from "@thi.ng/timestamp";
import { iterator1 } from "./iterator.js";
import { throttle } from "./throttle.js";
function throttleTime(delay, src) {
return isIterable(src) ? iterator1(throttleTime(delay), src) : throttle(() => {
let prev = now();
return () => {
const t = now();
return timeDiff(prev, t) >= delay ? (prev = t, true) : false;
};
});
}
export {
throttleTime
};