Skip to content

_.curry and _.mapValues no longer work together #917

@octref

Description

@octref

In 2.4.1, I was able to use

MixinObj =
  ciEquals: (s1, s2) ->
    s1.toLowerCase() is s2.toLowerCase()

# Currify and mixin

_.mixin(_.mapValues(MixinObj, _.curry))

In 3.0.1, the mixin functions are not correctly currified.
Whenever i try to use _.ciEquals,

  • _.ciEquals('a')
  • _.ciEquals('a', 'b')
  • _.ciEquals('a')('b')

all throws an error saying "TypeError: Cannot read property 'toLowerCase' of undefined".

I only roughly skimmed through the source code, in 2.4.1 you have a reasonable arity from

function curry(func, arity) {
  arity = typeof arity == 'number' ? arity : (+arity || func.length); // Reasonable arity
  return createWrapper(func, 4, null, null, null, arity);
}

But in 3.0.1 it's

function curry(func, arity, guard) {
  if (guard && isIterateeCall(func, arity, guard)) {
    arity = null;
  }
  var result = createWrapper(func, CURRY_FLAG, null, null, null, null, null, arity);
  result.placeholder = curry.placeholder;
  return result;
}

Why the arity validity check is gone? And why not get the arity from func.length when arity is not available?

When combined with _.mapValues

function mapValues(object, iteratee, thisArg) {
  var result = {};
  iteratee = getCallback(iteratee, thisArg, 3);

  baseForOwn(object, function(value, key, object) {
    result[key] = iteratee(value, key, object);
    // Here I only want iteratee(value), which would currify my function like this
    // curry(MixinObj.ciEquals)
    // But here it seems to be doing 
    // curry(MixinObj.ciEquals, "ciEquals", MixinObj)   
    // And "ciEquals" is apparently not a valid arity
  });
  return result;
}

See above, I wrote my problem as comments in the code for mapValues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions