Skip to content

Instantly share code, notes, and snippets.

@jakubbarczyk
Last active March 31, 2022 10:30
Show Gist options
  • Save jakubbarczyk/0804c1d16c15bfdfacc5bbf7fb983a8d to your computer and use it in GitHub Desktop.
Save jakubbarczyk/0804c1d16c15bfdfacc5bbf7fb983a8d to your computer and use it in GitHub Desktop.
Buffer max count operator for RxJS.
import { defer } from 'rxjs';
import { map } from 'rxjs/operators';
export const bufferMaxCount = (count = 0) => source => defer(() => {
let buffer = [];
return source.pipe(
map(next => buffer = [next, ...buffer.slice(0, count - 1)])
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment