Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Last active January 9, 2018 06:53
Show Gist options
  • Save jooyunghan/aa5766711616d6dee41fcaa2e9d1a8a7 to your computer and use it in GitHub Desktop.
Save jooyunghan/aa5766711616d6dee41fcaa2e9d1a8a7 to your computer and use it in GitHub Desktop.
traverse/sequence for JSArray
const traverse = (f, as) => sequence(map(f, as));
const sequence = (as) => {
if (as.length === 0) return [""];
return flatMap(a => map(b => [a, ...b], sequence(as.slice(1))), as[0])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment