Last active
January 9, 2018 06:53
-
-
Save jooyunghan/aa5766711616d6dee41fcaa2e9d1a8a7 to your computer and use it in GitHub Desktop.
traverse/sequence for JSArray
This file contains hidden or 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
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