- Mode: make(map[T]int) → make(map[T]int, len(collection))
- it.UniqKeys: compute total size from input maps for seen map hint
- it.UniqValues: compute total size from input maps for seen map hint
Avoids repeated map rehashing as entries are added.
* support for buffer iterator
* Code review fix
* fix: transforming the Buffer helper into a pull-based operator (it receives an iterator instead of channel)
* doc(it): adding loit.Buffer to doc
---------
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
Extract core logic into sliceNth/seqNth func returning (T, bool) instead of (T, error).
NthOr and NthOrEmpty now use these directly,
avoiding fmt.Errorf allocation when nth is out of bounds.
- RangeWithSteps now preallocates result slice using math.Ceil for better performance
- Fix edge cases for floating point values with small steps
- Add test cases for float and custom type validation
- Rename TestRangeClose → TestRangeWithSteps for consistency
- Simplify ChunkEntries chunk count calculation using ((count-1)/size)+1 formula
Replace shared next struct and reused stop variable with separate
nextA, stopA, nextB, stopB, etc.
Improves code clarity and eliminates potential confusion from variable reuse.
Change Trim to use DropLastWhile(DropWhile(...)) instead of DropWhile(DropLastWhile(...))
This is more efficient because DropWhile doesn't use a buffer, so it removes
leading elements first, then DropLastWhile works with a smaller collection.
Regression introduced in 1c66270 (perf: preallocate result slice in SamplesBy) where
`make(Slice, count)` with negative count causes panic. Previously used
`Slice{}` with `append`, which handled negative counts gracefully.
- Simplify NthOrEmpty by removing redundant error handling
- Simplify Sample by removing intermediate variable
- Refactor SamplesBy to use index tracking instead of collection copying
- More efficient: avoids copying the entire collection
- Uses Range to generate indexes and swaps/removes from index slice
- Uses `n := len(indexes)` to eliminate redundant bounds checks
- Add early return for count <= 0 in SamplesBy (fixes panic with make)
- Add edge case tests for SamplesBy:
- Test with deterministic random generators (always last index, always 0)
- Test count = 0 and count = -1 (verifies non-panic behavior)
- Add panic test for out-of-range index generation
Track exact duplicate count during detection phase instead of
incorrect estimating capacity as len(collection)-len(isDupl).
Also simplify map update logic and rename ok -> seen for clarity.
* 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
* 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.
* lint: fix inconsistent callback function parameter names
* lint: rename "iteratee" to "transform" for *Map helpers
* lint: rename "project" parameters to "transform"
* lint: rename "cb" parameters to "callback"
* lint: rename "iteratee" to "callback" for ForEach helpers
---------
Co-authored-by: Franky W. <frankywahl@users.noreply.github.com>
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
* feat: implementation of conversion from slice to map without index passed to transformation function through the similar conversion but with index passed to transformation function.
Signed-off-by: Marat Abrarov <abrarov@gmail.com>
* feat: implementation of conversion from iterator to map without index passed to transformation function through the similar conversion but with index passed to transformation function.
Signed-off-by: Marat Abrarov <abrarov@gmail.com>
---------
Signed-off-by: Marat Abrarov <abrarov@gmail.com>