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

curryRight is broken in list.map context #5828

Open
camyeoman opened this issue Mar 8, 2024 · 1 comment
Open

curryRight is broken in list.map context #5828

camyeoman opened this issue Mar 8, 2024 · 1 comment

Comments

@camyeoman
Copy link

The curryRight function normally works, but whenever I try and apply it in the map function it fails, complaining that the object is undefined. See the reproducible example below.

const fp = require("lodash");

function getProperty(property, obj) {
  const result = obj[property]
  if (result === undefined)
    throw new Error('result object is undefined')
  return result
};

const exampleObject = {
  id: '123'
};

const getPropOfObjectCurryR = fp.curryRight(getProperty)(exampleObject);
const getPropOfObjectCurryL = fp.curry(getProperty)(fp.curry.placeholder, exampleObject);

console.log(getPropOfObjectCurryL('id'));        // this does not throw missing error
console.log(getPropOfObjectCurryR('id'));        // this does not throw missing error
console.log(['id'].map(getPropOfObjectCurryL));  // this does not throw missing error
console.log(['id'].map(getPropOfObjectCurryR));  // this does throw the error

Note that is example was run using lodash version 4.17.21 and node version 16.19.0. Note that this is broken for both lodash and lodash/fp.

@berakoc
Copy link

berakoc commented Mar 27, 2024

['id'].map(key => getPropOfObjectCurryR(key));

In your code snippet the second parameter becomes the index of the mapper instead of object.

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

No branches or pull requests

2 participants