web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
457 B

  1. import arityN from 'arity-n';
  2. let compose2 = (f, g) => (...args) => f(g(...args));
  3. export default function compose(...functions) {
  4. const funcs = functions.filter(fn => typeof fn === 'function');
  5. let lastIdx = funcs.length - 1;
  6. let arity = 0;
  7. if (funcs.length <= 0) {
  8. throw new Error('No funcs passed');
  9. }
  10. if (lastIdx >= 0 && funcs[lastIdx]) {
  11. arity = funcs[lastIdx].length;
  12. }
  13. return arityN(funcs.reduce(compose2), arity);
  14. }