Commit Graph

38 Commits

Author SHA1 Message Date
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
Samuel Berthe 9cdabc1420 feat(perf): speed up some functions with linear complexity O=n2 -> O=2n (#726) 2025-11-05 19:07:43 +01:00
Nathan Baulch a7b807aec4 lint: use Keyify internally (#691) 2025-11-05 17:52:50 +01:00
Nathan Baulch f5aac81cc0 lint: enable gofumpt extra rules (#690)
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-09-26 13:32:59 +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 3e11f11781 docs: grammar improvements (#673)
* lint: pin golangci-lint version

* docs: grammar fixes

* docs: remove "truthy" terminology

* docs: remove "array" terminology

* docs: grammar fixes

* Update .github/workflows/lint.yml

---------

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-09-24 20:59:41 +02:00
Samuel Berthe 3bc887c57c doc: adding go playground examples 2025-09-23 14:54:30 +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 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
SnowOnion 9c6999edf6 docs: clarify Empty returns zero value (#543)
* 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>
2025-01-24 22:10:28 +01:00
nicklausliu c102c03738 feat: replace Without implementation by WithoutBy 2024-08-23 11:32:04 +08:00
nicklausliu 6e5a845f9f feat: impove WithoutBy performance 2024-08-23 11:20:46 +08:00
Nathan Baulch db0f4d2171 Tidy up (#519) 2024-08-22 01:17:02 +02:00
nicklausliu 3cf2fc4ba8 feat: modify WithoutBy function comment 2024-08-17 20:14:12 +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
Milo 7cce15b3d5 perf: Optimize the performance of union method, avoid repeated expansion (#397)
Co-authored-by: 逍遥 <caowenbo@shizhuang-inc.com>
2024-06-28 19:24:57 +02:00
Samuel Berthe 61209816d1 feat: speed up loops by reducing allocations (#475) 2024-06-28 01:35:57 +02:00
guanming a966a64cc6 Refactor Contains function to improve performance by using index iteration over collection (#428)
Co-authored-by: 关明 <guanming@ziipin.com>
2024-06-28 01:04:51 +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 7887963db8 feat: name each callback/iteratee/predicate arguments in order to improve autocompletion
closes #242
2022-10-13 22:25:33 +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
CorentinClabaut 86d419c07f PR Update 2022-04-28 15:24:55 +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
Xan 0cfa22a9fe add:intersect containsby 2022-03-08 15:22:00 +08:00
HirbodBehnam 1def922659 Use struct{} for sets 2022-03-05 22:00:44 +03:30
Samuel Berthe 74b7c77702 Initial commit 2022-03-02 13:52:01 +01:00