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

feat(func): add FuncWithIndex and FuncWithIndexNoReturn #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

quantumsheep
Copy link
Contributor

@quantumsheep quantumsheep commented Nov 28, 2024

Hey! I regularly write some functions that I pass to lo.Map and it's a hassle to have to pass the index every time.

Currently:

lo.Map(slice, func (v string, _ int) string {
	return doThing(v)
})

With the PR:

lo.Map(slice, lo.FuncWithIndex(doThing))

I'm not sure about the naming, it could simply be WithIndex.

I hope you like the idea.

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.35%. Comparing base (efef0ff) to head (7b493bc).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
+ Coverage   94.33%   94.35%   +0.01%     
==========================================
  Files          17       17              
  Lines        2790     2798       +8     
==========================================
+ Hits         2632     2640       +8     
  Misses        154      154              
  Partials        4        4              
Flag Coverage Δ
unittests 94.35% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@itroot
Copy link

itroot commented Nov 29, 2024

Wow. also faced that issue, and made a quite similar solution:

@quantumsheep
Copy link
Contributor Author

quantumsheep commented Nov 29, 2024

Wow. also faced that issue, and made a quite similar solution:

* [Curried map, reduce and filter for partial application  #330 (comment)](https://github.com/samber/lo/issues/330#issuecomment-2507770542)

Glad to see I'm not the only one wanting a feature like this :)

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

Successfully merging this pull request may close these issues.

2 participants