feat(func): add `FuncWithIndex` and `FuncWithIndexNoReturn`
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.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
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%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Wow. also faced that issue, and made a quite similar solution:
- https://github.com/samber/lo/issues/330#issuecomment-2507770542
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 :)
I agree.
But I would vote for duplicating lo.Map helper:
-
lo.Map -
lo.MapI
@samber lo.MapI would be the version with or without index?
If it's the one with index, I wonder if that's a good idea as it will break many projects. Or it will require a major update.
What do you think?
Yes 😅
I would break a large ecosystem. We would need to group all that changes into a single v2 major update.
I'm just sharing some ideas. Not telling we are going to do it right now 😇
Then I really prefer this option! I'm not sure how people use lo.Map right now but I guess the index argument is not that much used.
Is there a place where contributors can discuss the changes for v2? I would like to help 😄
@quantumsheep see #579