-
-
Save cobbweb/e939210541b587374fc0acb6df508950 to your computer and use it in GitHub Desktop.
Array.prototype.flatMap method in TypeScript.
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
interface Array<T> { | |
flatMap<E>(callback: (t: T) => Array<E>): Array<E> | |
} | |
Object.defineProperty(Array.prototype, 'flatMap', { | |
value: function(f: Function) { | |
return this.reduce((ys: any, x: any) => { | |
return ys.concat(f.call(this, x)) | |
}, []) | |
}, | |
enumerable: false, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment