Skip to content

Instantly share code, notes, and snippets.

@alvarogfn
Created March 23, 2023 17:21
Show Gist options
  • Save alvarogfn/2c905c9576c984caeb6a95101b7d0440 to your computer and use it in GitHub Desktop.
Save alvarogfn/2c905c9576c984caeb6a95101b7d0440 to your computer and use it in GitHub Desktop.
Debug Functions for Javascript/Typescript

Tap

A function that displays the content of a variable or function return on the console without compromising the flow.

Javascript:

  function tap(x, fn) {
    console.log(fn(x));
    return x;
  }

Typescript:

function tap<T>(x: T, fn: (x: T) => unknown = (x) => x): T {
  console.log(fn(x));
  return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment