Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active February 9, 2019 07:50
Show Gist options
  • Save cartant/40166d96207056edf618f17515c51448 to your computer and use it in GitHub Desktop.
Save cartant/40166d96207056edf618f17515c51448 to your computer and use it in GitHub Desktop.
import { MonoTypeOperatorFunction } from "rxjs";
import { tap } from "rxjs/operators";
export function debug<T>(): MonoTypeOperatorFunction<T> {
let index = -1;
// Let's pretend that the map operator doesn't exist and that we have to use
// the tap operator and maintain our own internal state for the index, as the
// purpose of our operator is to show that the behaviour depends upon where
// the state is stored.
return tap(t => console.log(`[${++index}]: ${t}`));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment