Skip to content

Instantly share code, notes, and snippets.

View ichpuchtli's full-sized avatar

Sam Macpherson ichpuchtli

View GitHub Profile
@ichpuchtli
ichpuchtli / flatMap.ts
Last active February 22, 2016 13:19 — forked from samgiles/flatMap.js
Javascript flatMap implementation
// [B](f: (A) ⇒ [B]): [B] ; Although the types in the arrays aren't strict (:
function flatMap<T, U>(array: T[], mapFunc: (x: T) => U[]) : U[] {
return array.reduce((cumulus: U[], next: T) => [...mapFunc(next), ...cumulus], <U[]> []);
}