* refactor: improve lo[it].Intersect[By] readability and performance
Preallocate seen map capacity.
Extract first and last list handling out of the main loop.
Remove redundant map traversal by combining the reset and delete
passes into a single loop. Values are now initialized to false and
toggled to true when found, allowing the cleanup pass to both reset
(true→false) and delete in one iteration.
Move len(seen) == 0 check into loop condition, allowing early exit
before processing next list when intersection becomes empty
(skips redundant first iteration).
* fix([it].Intersect[By]): remove incorrect early return for single list
The special case `if len(lists) == 1 { return lists[0] }` was buggy:
- Returned the original slice instead of a new one
- Did not deduplicate elements
Removing it allows the general algorithm to handle single lists
correctly by creating a new slice with unique elements.
* feat(intersectby): form transform callback in first position and add support for vaarg
* feat(it): adding loit.IntersectBy
* doc: adding lo.IntersectBy + loit.IntersectBy
* doc: adding lo.IntersectBy + loit.IntersectBy
* style: fix linter
* doc: adding example for lo.IntersectBy
* Update README.md
Fixed the error in the usage example of lo.Latest in readme.md
use []time.Time{…} (value of type []time.Time) as time.Time value in argument to lo.Latest
* Update README.md
* feature: add Mode function with tests and documentation
* feat: Add IntersectBy function and tests, supporting intersection by custom key sets
---------
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
* Fix linting
* Use is.ElementsMatch
This will ignore the ordering of the final intersection. Especially
important when checking old versions of go that do not guarantee an order
when iterating through maps.
* perf: only allocate a single map in Intersect
* chore: improve test coverage
---------
Co-authored-by: Franky W. <frankywahl@users.noreply.github.com>
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
* Fix linting
* Use is.ElementsMatch
This will ignore the ordering of the final intersection. Especially
important when checking old versions of go that do not guarantee an order
when iterating through maps.
* Allow Union to take many lists
* Allow Intersect to take many lists
* Allow for any number of intersection arguments
* Do not use recursion
Optimize Intersect to avoid using recursion and reduce computation
* Add ExampleIntersect
Adds an example test for intersect
* Add example for Intersect in Readme
* Update docs for Intersect
* lint: pin golangci-lint version
* feat: preserve type alias in WithoutBy
* feat: preserve type alias in DropByIndex
---------
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
* docs: clarify `Empty` returns zero value
https://go.dev/ref/spec#The_zero_value does not define "empty value". It informally mentions "empty value", meaning (non-nil && 0-length) slice or map.
> Note that the zero value for a slice or map type is not the same as an initialized but empty value of the same type.
* docs: other "empty value" -> "zero value"
---------
Co-authored-by: xuanhong <litianchi@papegames.net>
* Add function Without which return slice with slice all elements not in another
* feat(Without): inverse args and use variadic argment for excluding items
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>