Skip to content
New issue

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

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

Already on GitHub? # to your account

Support for findKey, findLastKey #715

Open
Na-hyunwoo opened this issue Oct 15, 2024 · 2 comments
Open

Support for findKey, findLastKey #715

Na-hyunwoo opened this issue Oct 15, 2024 · 2 comments

Comments

@Na-hyunwoo
Copy link
Contributor

Hi, @raon0211 !
Can I work findKey of #91 ??

#441
In the above issue, someone said they were implementing it, but it seems like it hasn't been implemented because it's been about 2 months.

And I have a question about the findKey interface.

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

_.findKey(users, function(o) { return o.age < 40; });
// => 'barney' (iteration order is not guaranteed)
 
// The `_.matches` iteratee shorthand.
_.findKey(users, { 'age': 1, 'active': true });
// => 'pebbles'
 
// The `_.matchesProperty` iteratee shorthand.
_.findKey(users, ['active', false]);
// => 'fred'
 
// The `_.property` iteratee shorthand.
_.findKey(users, 'active');
// => 'barney'

Looking at the example in the lodash document, you can get the key by entering ['active', false] or 'active' as the second argument to findKey, but this makes the complexity of implementation very difficult.

https://github.com/toss/es-toolkit/blob/main/.github/CONTRIBUTING.md

However, if you look at es-toolkit's design priniciples, it emphasizes simplicity.

So I think that implementing only the first and second interfaces in the above example fits es-toolkit's priniciples.

However, if that happens, the interface will be different from lodash, so I think there might be a problem during the switching process in lodash.

Of these two conflicting issues principles vs compatibility with lodash, which issue has higher priority?

@raon0211
Copy link
Collaborator

Sure :)

What about supporting only functions in our original es-toolkit library, and supporting matches and matchesProperty, etc. in our compatibility library?

You can refer to how we approached this problem in dropWhile or other similar functions.

@Na-hyunwoo
Copy link
Contributor Author

That would work!!

Thank you for your good comments.

Let’s implement it by referring to the dropWhile example 🙏

@Na-hyunwoo Na-hyunwoo changed the title Support for findKey Support for findKey, findLastKey Oct 27, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants