Skip to content

Instantly share code, notes, and snippets.

View tjventurini's full-sized avatar
💭
🚀

Thomas Venturini tjventurini

💭
🚀
View GitHub Profile
@lorisleiva
lorisleiva / pipeline.js
Last active February 23, 2023 17:28
Laravel-like pipelines in JavaScript and TypeScript
export function pipeline(initialValue, pipes, then) {
then = then ?? ((t) => t);
const pipelineCallback = pipes
.slice()
.reverse()
.reduce((next, pipe) => (passable) => pipe(passable, next), then);
return pipelineCallback(initialValue);
}