Inspired by the following Tweet from Eric Elliot in which he uses a reducer to make a pipe function, I thought I'd do something similar in Python and F#.
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x);— Eric Elliott (@_ericelliott) April 1, 2020
const g = n => n + 1;
const f = n => n * 2;
const h = pipe(g, f);
h(20); // 42
pipe = lambda *fns: lambda x: reduce(lambda y, f: f(y), list(fns), x) g = lambda n: n + 1 f = lambda n: n * 2 h = pipe(g, f) h(20) # 42
Then, of course, in F# it's a native operator in the language so the same pipeline is beautifully brief.
let g n = n + 1 let f n = n * 2 let h a = a |> g |> f h 20 // 42