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.

partialRight.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var baseRest = require('./_baseRest'),
  2. createWrap = require('./_createWrap'),
  3. getHolder = require('./_getHolder'),
  4. replaceHolders = require('./_replaceHolders');
  5. /** Used to compose bitmasks for function metadata. */
  6. var WRAP_PARTIAL_RIGHT_FLAG = 64;
  7. /**
  8. * This method is like `_.partial` except that partially applied arguments
  9. * are appended to the arguments it receives.
  10. *
  11. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  12. * builds, may be used as a placeholder for partially applied arguments.
  13. *
  14. * **Note:** This method doesn't set the "length" property of partially
  15. * applied functions.
  16. *
  17. * @static
  18. * @memberOf _
  19. * @since 1.0.0
  20. * @category Function
  21. * @param {Function} func The function to partially apply arguments to.
  22. * @param {...*} [partials] The arguments to be partially applied.
  23. * @returns {Function} Returns the new partially applied function.
  24. * @example
  25. *
  26. * function greet(greeting, name) {
  27. * return greeting + ' ' + name;
  28. * }
  29. *
  30. * var greetFred = _.partialRight(greet, 'fred');
  31. * greetFred('hi');
  32. * // => 'hi fred'
  33. *
  34. * // Partially applied with placeholders.
  35. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  36. * sayHelloTo('fred');
  37. * // => 'hello fred'
  38. */
  39. var partialRight = baseRest(function(func, partials) {
  40. var holders = replaceHolders(partials, getHolder(partialRight));
  41. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  42. });
  43. // Assign default placeholders.
  44. partialRight.placeholder = {};
  45. module.exports = partialRight;