_curry3.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import _curry1 from "./_curry1.js";
  2. import _curry2 from "./_curry2.js";
  3. import _isPlaceholder from "./_isPlaceholder.js";
  4. /**
  5. * Optimized internal three-arity curry function.
  6. *
  7. * @private
  8. * @category Function
  9. * @param {Function} fn The function to curry.
  10. * @return {Function} The curried function.
  11. */
  12. export default function _curry3(fn) {
  13. return function f3(a, b, c) {
  14. switch (arguments.length) {
  15. case 0:
  16. return f3;
  17. case 1:
  18. return _isPlaceholder(a) ? f3 : _curry2(function (_b, _c) {
  19. return fn(a, _b, _c);
  20. });
  21. case 2:
  22. return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function (_a, _c) {
  23. return fn(_a, b, _c);
  24. }) : _isPlaceholder(b) ? _curry2(function (_b, _c) {
  25. return fn(a, _b, _c);
  26. }) : _curry1(function (_c) {
  27. return fn(a, b, _c);
  28. });
  29. default:
  30. return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function (_a, _b) {
  31. return fn(_a, _b, c);
  32. }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function (_a, _c) {
  33. return fn(_a, b, _c);
  34. }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function (_b, _c) {
  35. return fn(a, _b, _c);
  36. }) : _isPlaceholder(a) ? _curry1(function (_a) {
  37. return fn(_a, b, c);
  38. }) : _isPlaceholder(b) ? _curry1(function (_b) {
  39. return fn(a, _b, c);
  40. }) : _isPlaceholder(c) ? _curry1(function (_c) {
  41. return fn(a, b, _c);
  42. }) : fn(a, b, c);
  43. }
  44. };
  45. }