-
Notifications
You must be signed in to change notification settings - Fork 0
restrictAfter
Subhajit Sahu edited this page Jul 22, 2022
·
2 revisions
Restrict a function to be used only after a certain number of calls.
Alternatives: [restrict], [restrictOnce], [restrictBefore], restrictAfter.
function restrictAfter(x, n)
// x: a function
// n: number of calls after which it is usable
const {restrictAfter} = require('extra-function');
var count = 0;
var fn = restrictAfter(x => ++count, 3);
for (var i=0; i<10; ++i)
fn(i);
count;
// → 7