Skip to content

Instantly share code, notes, and snippets.

@AndreasLoukakis
Created April 23, 2017 22:38
Show Gist options
  • Save AndreasLoukakis/8799e9e01e4c268c4bf1be6b35c3e7f7 to your computer and use it in GitHub Desktop.
Save AndreasLoukakis/8799e9e01e4c268c4bf1be6b35c3e7f7 to your computer and use it in GitHub Desktop.
various implementations of pipe in JS
// curried with arrows
const composeMixins = (...mixins) => (
instance = {},
mix = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x)
) => mix(...mixins)(instance);
// vs ES5-style
var composeMixins = function () {
var mixins = [].slice.call(arguments);
return function (instance, mix) {
if (!instance) instance = {};
if (!mix) {
mix = function () {
var fns = [].slice.call(arguments);
return function (x) {
return fns.reduce(function (acc, fn) {
return fn(acc);
}, x);
};
};
}
return mix.apply(null, mixins)(instance);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment