Published
Edited
Dec 6, 2018
Insert cell
Insert cell
function pipe (A) {
return (f) => {
mutable count += 1 // (log when this function is evaluated)
if (!f) return A
return pipe(f(A))
}
}
// can be written briefly as f = A => g => g ? A : f(g(A))
// Usage:
// pipe(object)(a => b)(b => c)...(y => z)() // returns z
// useful for declarative programming pipelines
Insert cell
pipe('a')
(a => a + 'b')
(b => b + 'c')
(c => c + 'd')
()
Insert cell
{
// function evaluations are immediate, so we don't have to worry about stack overflow
mutable count = 0
const pipeline = pipe('a')
(a => a + 'b')
(b => b + 'c')
(c => c + 'd')
const prior_evaluations = mutable count
mutable count = 0
const output = pipeline()
const final_evaluations = mutable count
return [prior_evaluations, final_evaluations]
}
Insert cell
mutable count = 0
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more