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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more