Created
December 12, 2020 00:41
-
-
Save cartant/2755d2b3f85fa650b617e6cabdc823b3 to your computer and use it in GitHub Desktop.
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
export const windowBy = <K, T>( | |
keyFn: (t: T) => K | |
): OperatorFunction<T, GroupedObservable<K, T>> => (source) => source.pipe( | |
publish((sharedSource) => { | |
const newWindow = sharedSource.pipe( | |
distinctUntilChanged((a, b) => keyFn(a) === keyFn(b)) | |
); | |
return sharedSource.pipe( | |
groupBy(keyFn, undefined, () => | |
newWindow.pipe( | |
// Skip the first window as that is what created the current group. | |
skip(1) | |
) | |
) | |
); | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment