interface Array { flatJoinOn(by: (item: T) => J): Array; } Array.prototype.flatJoinOn = function (f: Function) { return this.groupBy(f).reduce((ys: any, x: any) => { return ys.concat(f.call(this, x)); }, []); };