Conversation
|
Also might be worth incorporating the suggestion from #16 since there are no limits to the number of goroutines that can be started. |
|
Hey @samber do you have time to look at this? |
|
But the implementation of |
parallel/slice.go
Outdated
|
|
||
| // Map manipulates a slice and transforms it to a slice of another type. | ||
| // `iteratee` is call in parallel. Result keep the same order. | ||
| // `iteratee` is called in parallel. Result keep the same order. |
There was a problem hiding this comment.
This change should be in a separate MR.
6c9f8a1 to
ff2ce49
Compare
|
I removed the errGroup import and the comment fix |
|
@samber what do you think? |
|
Hi, i'm very interesting about this 👍🏻 |
|
Bump again @samber |
|
I also agree with the value of this PR |
|
It will be the best Christmas gift if it gets merged. |
So true |
|
:sadge: I've been thinking about forking lo to get MapWithError for a while now. Keep hoping this will get merged but looks pretty dead. |
|
@samber could you please review this. 🙏 We all see community needs it! 🙂 |
|
✅ Done in #823 Please upgrade to v1.53.0 |
This pr adds both lo.MapWithError and lop.MapWithError.
This is very useful if your internal function returns an error and you want to short circuit the Map. Currently you can keep track of an error outside of Map, however it won't short circuit the mapping and any subsequent errors will overwrite each other. This is a common situation when doing anything io related.
To implement the parallel version I included the
golang.org/x/sync/errgrouppackage in order to useerrgroup.Groupwhich implements go routine cancellation.This is what lo.MapWithError looks like:
Here is a less contrived example of lop.MapWithError that shows parallel http requests that could error.