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

(FP) invoke does not work with arguments #5753

Open
jinusean opened this issue Oct 13, 2023 · 3 comments
Open

(FP) invoke does not work with arguments #5753

jinusean opened this issue Oct 13, 2023 · 3 comments

Comments

@jinusean
Copy link

jinusean commented Oct 13, 2023

The example code returns undefined

var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };

_.invoke(['a[0].b.c.slice', 1, 3], object);

invoke does work without arguments however..

@Lsnsh
Copy link

Lsnsh commented Oct 19, 2023

_.invoke(object, path, [args])

Invokes the method at path of object.

Arguments

object (Object): The object to query.
path (Array|string): The path of the method to invoke.
[args] (...*): The arguments to invoke the method with.

May be need adjust the arguments position:

var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
 
_.invoke(object, 'a[0].b.c.slice', 1, 3);
// => [2, 3]

https://lodash.com/docs/4.17.15#invoke

@jinusean
Copy link
Author

_.invoke(object, path, [args])
Invokes the method at path of object.
Arguments
object (Object): The object to query.
path (Array|string): The path of the method to invoke.
[args] (...*): The arguments to invoke the method with.

May be need adjust the arguments position:

var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
 
_.invoke(object, 'a[0].b.c.slice', 1, 3);
// => [2, 3]

https://lodash.com/docs/4.17.15#invoke

Even for the fp version of lodash?

@Lsnsh
Copy link

Lsnsh commented Oct 24, 2023

For FP(lodash/fp), may be need adjust the arguments position:

// Load the fp build.
var fp = require("lodash/fp");

var object = { a: [{ b: { c: [1, 2, 3, 4] } }] };

var ret = fp.invokeArgs("a[0].b.c.slice")([1, 3])(object);
console.log(ret);
// => [ 2, 3 ]

ret = fp.invokeArgs("a[0].b.c.slice", [1, 3], object);
console.log(ret);
// => [ 2, 3 ]

More info see:

FP Guide:
https://github.com/lodash/lodash/wiki/FP-Guide#rearranged-arguments
https://github.com/lodash/lodash/wiki/FP-Guide#new-methods

fp.invoke and fp.invokeArgs related TS type definition:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/68596a5a676dad481ef4db52a023e4ca5ad7268a/types/lodash/fp.d.ts#L1815-L1850

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