Allow Union/Intersect to take many lists#181
Conversation
6725a7e to
816e26c
Compare
|
@samber Any updates on this, I've updated it recently given that |
0938e08 to
25769db
Compare
intersect.go
Outdated
| for _, elem := range lists[len(lists)-1] { | ||
| if _, ok := seen[elem]; ok { | ||
| result = append(result, elem) | ||
| } | ||
| } | ||
|
|
||
| return result | ||
| lists[0] = result | ||
|
|
||
| return Intersect(lists[:len(lists)-1]...) |
There was a problem hiding this comment.
please don't perform recursion since it will require extra computation
for i := 1; i < len(lists); i++ {
for j := 0; j < len(lists[i]); j++ {
if _, ok := seen[lists[i][j]]; !ok {
delete(seen, lists[i][j])
}
}
if len(seen) == 0 {
return Slice{}
}
}
return Keys(seen)|
Please add an example in lo_example.go and update documentation in README.md and docs/ |
Optimize Intersect to avoid using recursion and reduce computation
Adds an example test for intersect
|
This breaks CI due to a minor linting issue @samber @frankywahl. Do CI failures not block PR merges? |
Sorry about this, fixed it in #731 |
|
@frankywahl i usually don't block PRs with linting issues to avoid round-trip and delays for merge. And sometimes, I forget to apply the fix on the master branch 😅 |
Allow a union & intersect of any number of lists.
I also thought about changing the API to for more flexibility:
This would be backward compatible, but would change the required number of arguments, so left it as it was for now. Happy to change it.
Update: since the PR was opened, Union was changed to take a variadic list. So I've updated this PR to have the same method signature.