Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active February 9, 2019 07:25
Show Gist options
  • Save cartant/59123c03164a075c8a5ec2582b782aac to your computer and use it in GitHub Desktop.
Save cartant/59123c03164a075c8a5ec2582b782aac to your computer and use it in GitHub Desktop.
import { MonoTypeOperatorFunction } from "rxjs";
import { map, scan } from "rxjs/operators";
export function debug<T>(): MonoTypeOperatorFunction<T> {
return source => source.pipe(
scan<T, [T, number]>(([, index], t) => [t, index + 1], [undefined!, -1]),
map(([t, index]) => (console.log(`[${index}]: ${t}`), t))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment