Fix flat map

Fixes a bug which was breaking flatMap
This commit is contained in:
Sean Engelhardt 2020-01-29 12:47:42 +01:00
parent 8012bfbfc0
commit 6f114d0072

View File

@ -142,11 +142,12 @@ export class AppComponent {
* TODO: Remove once flatMap made its way into official JS/TS (ES 2019?)
*/
private overloadFlatMap(): void {
const concat = (x: any, y: any) => x.concat(y);
const flatMap = (f: any, xs: any) => xs.map(f).reduce(concat, []);
Object.defineProperty(Array.prototype, 'flatMap', {
value: flatMap,
value: function(o: any): any[] {
const concatFunction = (x: any, y: any[]) => x.concat(y);
const flatMapLogic = (f: any, xs: any) => xs.map(f).reduce(concatFunction, []);
return flatMapLogic(o, this);
},
enumerable: false
});
}