Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for after #158

Closed
haejunejung opened this issue Jul 11, 2024 · 2 comments · Fixed by #258
Closed

Support for after #158

haejunejung opened this issue Jul 11, 2024 · 2 comments · Fixed by #258

Comments

@haejunejung
Copy link
Contributor

As I mentioned in #153, I will proceed with the after :) @raon0211!

@raon0211
Copy link
Collaborator

Sure!

@haejunejung
Copy link
Contributor Author

I've implemented this :)

export const after = <P, F extends (...args: any[]) => P>(n: number, func: F): F => {
  if (!Number.isInteger(n) || n < 1) {
    throw new Error(`n must be an integer greater than or equal to one.`);
  }

  let counter = 1;
  return ((...args: Parameters<F>) => {
    if (counter >= n) {
      return func(...args);
    }
    counter++;
  }) as F;
};

If it looks good, I proceed with enhancing the documentation and test and then I submit a pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants