Skip to content

Instantly share code, notes, and snippets.

@subhaze
Last active April 19, 2016 23:57
Show Gist options
  • Save subhaze/4f62ed62303a06051d6767410c98ca09 to your computer and use it in GitHub Desktop.
Save subhaze/4f62ed62303a06051d6767410c98ca09 to your computer and use it in GitHub Desktop.
pipeline [Array#reduce]
<pre style="padding: 20px"><code class="hljs js">
function pipeline(data, ...fns){
return fns.reduce((acc, curr) => curr(acc), data);
}
let abc = pipeline('a', (v)=>v+'b', (v)=>v+'c');
console.log(abc);
// "abc"
</code></pre>
function pipeline(data, ...fns){
return fns.reduce((acc, curr) => curr(acc), data);
}
let abc = pipeline('a', (v)=>v+'b', (v)=>v+'c');
console.log(abc);
hljs.initHighlightingOnLoad()
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/tomorrow-night-eighties.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment