Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: R.curryN with R.__ placeholder #2815

Open
objectisundefined opened this issue May 5, 2019 · 3 comments
Open

Question: R.curryN with R.__ placeholder #2815

objectisundefined opened this issue May 5, 2019 · 3 comments
Labels

Comments

@objectisundefined
Copy link
Contributor

// R.curry document example
var f = (a, b, c) => [a, b, c]
var g = R.curry(f)

// _ is R.__
// what should g(1, _)(_, 2, _, 'a') returns?
// result is [ 1, _, 2 ] now

Ramda doesn't limit arguments length, but it also reduces left arguments length when
combinedIdx is larger than fn's length

// src/internal/_curryN.js

function _curryN(length, received, fn) {
  return function () {
    var combined = [];
    var argsIdx = 0;
    var left = length;
    var combinedIdx = 0;
    while (combinedIdx < received.length || argsIdx < arguments.length) {
      var result;
      if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) {
        result = received[combinedIdx];
      } else {
        result = arguments[argsIdx];
        argsIdx += 1;
      }
      combined[combinedIdx] = result;
      if (!_isPlaceholder(result)) {
        left -= 1;
      }
      combinedIdx += 1;
    }
    return left <= 0 ? fn.apply(this, combined) : _arity(left, _curryN(length, combined, fn));
  };
}
@CrossEye
Copy link
Member

CrossEye commented May 9, 2019

This does seem far less than ideal. Do you have a recommendation?

Note that g(1)(_, 2, _, 'a') is a simpler demonstration.

@objectisundefined
Copy link
Contributor Author

objectisundefined commented May 9, 2019

Should we call fn when all placeholders were filled? Or only check placeholders in the first N args?

@CrossEye
Copy link
Member

CrossEye commented May 9, 2019

In keeping with other Ramda functions, I would like to pass along extra arguments if they're supplied. So g(1)(_, 3)(2, 'a') should yield f(1, 2, 3, 'a'), even though f only has arity 3.

But it's not clear to me what the behavior of g(1)(_, 2, _, 'a') should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants