Created
April 23, 2017 22:38
-
-
Save AndreasLoukakis/8799e9e01e4c268c4bf1be6b35c3e7f7 to your computer and use it in GitHub Desktop.
various implementations of pipe in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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