Last active
January 17, 2020 04:50
-
-
Save irrationnelle/d0f729f7dedc99e57c0c209a16ab5bfd 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
import { from } from "rxjs"; | |
import { bufferCount, concatMap, last, mergeMap, scan } from "rxjs/operators"; | |
class Test { | |
someArray = [1,2,3,4,5,6,7,8,9,10,11,12]; | |
constructor() { | |
from(this.someArray).pipe( | |
bufferCount(3), | |
concatMap((dividedArray: number[]) => | |
from(dividedArray).pipe( | |
mergeMap(this.delayedPromise), | |
scan((acc: number[], curr: number) => [...acc, curr], []), | |
last() | |
) | |
), | |
).subscribe(console.log) | |
} | |
delayedPromise = (n: number): Promise<number> => new Promise((resolve => { | |
setTimeout(() => { | |
resolve(n+1) | |
}, this.getRandomArbitrary(100, 1000)) | |
})); | |
getRandomArbitrary = (min: number, max: number): number => Math.random() * (max - min) + min; | |
} | |
const test = new Test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment