For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/function/after.md.

after es-toolkit

Creates a new function that invokes the original function starting from the n-th call.

const afterFunc = after(n, func);

Usage

after(n, func)

Use after when you want to ignore the first few calls and execute the function starting from the n-th call. This is useful when you need to perform an action only after a specific number of occurrences in events or asynchronous operations.

import { after } from 'es-toolkit/function';

const afterFn = after(3, () => {
  console.log('executed');
});

// logs nothing
afterFn();
// logs nothing
afterFn();
// logs 'executed'
afterFn();
// logs 'executed'
afterFn();

Parameters

nnumberrequired

The number of calls required before func is executed.

funcFrequired

The function to be executed.

Returns

A new function that tracks the number of calls and executes func starting from the n-th call. Returns undefined for calls before the n-th call.

(...args: Parameters<F>) => ReturnType<F> | undefined

Throws

Throws an error when n is not an integer or is negative.

Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.