30 Commits

Author SHA1 Message Date
Samuel Berthe cd78292882 💄 2026-03-02 16:06:51 +01:00
Samuel Berthe 1da649cc26 feat: adding WithoutByErr helper 2026-03-02 16:06:51 +01:00
Uri Simchoni db119e7d60 WithoutNth handle non-comparable types (#774)
Because filtering is by index, WithoutNth can handle any
type.

Co-authored-by: Uri Simchoni <uri@vfunction.com>
2026-01-12 21:01:28 +01:00
d-enk a2553e57bb refactor: improve lo[it].Intersect[By] readability and performance (#756)
* 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.
2026-01-08 17:54:23 +01:00
Samuel Berthe d99edab80d Refactoring lo.IntersectBy + adding loit.IntersectBy + adding doc (#739)
* 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
2025-11-07 01:23:34 +01:00
ghosx 43ae3d74da Feature/intersect by (#653)
* 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>
2025-11-06 21:14:54 +01:00
Nathan Baulch 4782f597b1 perf: only allocate a single map in Intersect (#736)
* 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>
2025-11-06 16:16:14 +01:00
Franky W. 3f2e24e875 Intersect CI test fix (#731)
* 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.
2025-11-06 16:03:38 +01:00
Franky W. ed8ee742a6 Allow Union/Intersect to take many lists (#181)
* 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
2025-11-05 23:04:41 +01:00
Nathan Baulch 52d31f788f lint: fix CI warnings and avoid named return parameters (#682) 2025-09-25 03:44:33 +02:00
Nathan Baulch 41cbf0fd2b feat: preserve type alias in DropByIndex and WithoutBy (#675)
* 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>
2025-09-24 22:57:40 +02:00
Nathan Baulch 7170719ec0 lint: unit test improvements (#674)
* lint: pin golangci-lint version

* lint: use is.Empty where possible

* lint: use is.ElementsMatch for unsorted slices

* lint: remove redundant is.Len assertions

* lint: use is.Zero to assert zero structs

* fix: misc assertion issues

* lint: more consistent test case pattern

* fix: reversed expect/actual assert values

* lint: use is.ErrorIs and is.EqualError for errors

* Update golangci-lint version in workflow

---------

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-09-24 21:02:52 +02:00
Nathan Baulch 76b76a7adb lint: Apply testifylint linter recommendations (#669) 2025-09-20 00:50:00 +02:00
Samuel Berthe 579fdad713 feat: adding FilterValues and fix FilterKeys signature (#661)
* feat: adding FilterValues and fix FilterKeys signature

* oops
2025-08-24 12:43:12 +02:00
Oganes Mirzoyan 4a43ff68b4 Add ElementsMatch, ElementsMatchBy (#589)
* Add ElementsMatch, ElementsMatchBy

* Update intersect.go

* Update README.md

---------

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-04-26 19:06:51 +02:00
Samuel Berthe 6b110b3c4f test(withoutempty): missing test 2025-01-26 18:10:37 +01:00
Samuel Berthe 33f7b14d1d Merge branch 'master' into nick-add-without-by 2025-01-25 23:40:21 +01:00
Samuel Berthe 8e64522eb6 feat: adding WithoutNth (#575) 2025-01-25 18:18:48 +01:00
nicklausliu 4f1f56a930 feat: convert Test struct to exported 2024-08-18 14:47:17 +08:00
nicklausliu 107d5794c3 feat: add WithoutBy 2024-08-15 11:52:22 +08:00
Samuel Berthe 3ba93a16cc feat: preserve type alias of slices and maps (see #365) 2024-06-30 00:04:08 +02:00
H 6a2a333ded feat: improve Union (#245)
Co-authored-by: hhu <hhu@tencent.com>
2022-10-14 17:55:11 +02:00
Samuel Berthe 31f3bc3a85 test: parallel tests everywhere (#228) 2022-10-02 21:38:26 +02:00
Samuel Berthe 198c67fbf8 feat: adding WithoutEmpty 2022-07-04 10:20:52 +02:00
chensy 07fddc1640 Add function Without which return slice with slice all elements not i… (#142)
* 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>
2022-07-04 10:17:03 +02:00
lu4p 305f565368 remove unnecessary explicit typeparams (#134) 2022-05-11 13:10:36 +02:00
CorentinClabaut a043a269c0 Merge branch 'master' into AllAnyNone 2022-04-12 09:00:01 +02:00
xuzhiwei 2587bfdac0 Add Union 2022-03-10 14:48:41 +08:00
Xan 2491b05d09 update:intersect containsby utest 2022-03-08 15:52:40 +08:00
Samuel Berthe 74b7c77702 Initial commit 2022-03-02 13:52:01 +01:00