liftAll.js 807 B

12345678910111213141516171819202122232425262728
  1. /** @license MIT License (c) copyright 2010-2014 original author or authors */
  2. /** @author Brian Cavalier */
  3. /** @author John Hann */
  4. (function(define) { 'use strict';
  5. define(function() {
  6. return function liftAll(liftOne, combine, dst, src) {
  7. if(typeof combine === 'undefined') {
  8. combine = defaultCombine;
  9. }
  10. return Object.keys(src).reduce(function(dst, key) {
  11. var f = src[key];
  12. return typeof f === 'function' ? combine(dst, liftOne(f), key) : dst;
  13. }, typeof dst === 'undefined' ? defaultDst(src) : dst);
  14. };
  15. function defaultCombine(o, f, k) {
  16. o[k] = f;
  17. return o;
  18. }
  19. function defaultDst(src) {
  20. return typeof src === 'function' ? src.bind() : Object.create(src);
  21. }
  22. });
  23. }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));