Last active
March 31, 2022 10:30
-
-
Save jakubbarczyk/0804c1d16c15bfdfacc5bbf7fb983a8d to your computer and use it in GitHub Desktop.
Buffer max count operator for RxJS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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