Skip to content

Instantly share code, notes, and snippets.

@pete-murphy
Created January 14, 2019 16:27
Show Gist options
  • Save pete-murphy/581f7f5c416e4f27effeafe93a6cd925 to your computer and use it in GitHub Desktop.
Save pete-murphy/581f7f5c416e4f27effeafe93a6cd925 to your computer and use it in GitHub Desktop.
Curios (AKA stealing functions from Haskell)
// This one is based off a Mark Seeman blog post.
// He gives examples in Haskell (using `sprintf` magic)
// The cool thing is that in JavaScript we have
// n-ary (AKA variadic) functions. So this works:
liftN(6, (...args) => args.join(""))(
["P", "p"],
["a", "4"],
["ssw"],
["o", "0"],
["rd"],
["", "!"]
)
// I think this returns the same thing:
map(xs => xs.join(""))(
sequence(Array.of, [
["P", "p"],
["a", "4"],
["ssw"],
["o", "0"],
["rd"],
["", "!"]
])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment