Skip to content

Instantly share code, notes, and snippets.

@christianscott
Created March 24, 2018 08:47
Show Gist options
  • Save christianscott/9fbbe69040d9081afc6673faa61ba67e to your computer and use it in GitHub Desktop.
Save christianscott/9fbbe69040d9081afc6673faa61ba67e to your computer and use it in GitHub Desktop.
HOF to add `pipe` method to any function
const assert = require("assert")
function pipes(func) {
return function () {
const value = func.apply(null, arguments)
return {
value,
pipe(func2) {
return func2(value)
}
}
}
}
const _add = (a, b) => a + b
const add = pipes(_add)
assert(
add(10, 10)
.pipe(x => x + 1) === 21,
"should pipe"
)
assert(
add(10, 10).value === 20,
"should expose value"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment