Commit graph

97 commits

Author SHA1 Message Date
46d52e3cfa
perf: pre-allocate Partition result slices
Adds capacity hints to both keep and reject slices in Partition
function to prevent repeated allocations during append operations.

Changes:
- keep: make([]T, 0) → make([]T, 0, len(values))
- reject: make([]T, 0) → make([]T, 0, len(values))

Impact:
- Reduces allocations from O(log n) to O(1) for each slice
- Improves performance by eliminating slice growth overhead
- Minimal memory overhead as worst case is original slice size

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 13:48:28 +01:00
7caa23e082
perf: replace bubble sort with slices.SortFunc in OrderBy
Replaces O(n²) bubble sort algorithm with O(n log n) slices.SortFunc
from the standard library, delivering massive performance improvements.

Performance improvements:
- Large dataset (1000 items): 2,121,531 ns/op → 3,372 ns/op (629x faster!)
- Small dataset (10 items): 199 ns/op → 178 ns/op (10% faster)
- Time reduction: 99.84% for large datasets

Resolves the TODO comment about replacing the simple algorithm.

Also adds comprehensive benchmarks for both small and large datasets
to track performance regressions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 13:46:22 +01:00
92b64630dc
perf: pre-allocate Filter result slice
Improves Filter performance by pre-allocating result slice with
input capacity instead of growing dynamically.

Performance improvements:
- Time: 1867 ns/op → 1717 ns/op (8% faster)
- Allocations: 10 → 1 (90% reduction)

This significantly reduces GC pressure for high-frequency operations.

Also updates Join test to expect empty slice [] instead of nil,
which is better Go practice.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 13:44:07 +01:00
7580836815
docs(readme): update usage, API, and utilities sections
Update README to use the latest version in install instructions, expand
the
list of available API functions, and add documentation for new utilities
and
subpackages. Improves clarity and completeness for users.
2025-11-14 13:36:51 +01:00
c53d46816f
refactor: migrate to Go 1.22 slices/cmp, update linters
Replace usage of golang.org/x/exp/constraints with Go 1.22 cmp/slices.
Update .golangci.yml to new v2 format and enable gofmt/goimports.
Refactor imports and type constraints across codebase for consistency.
2025-09-01 23:08:10 -04:00
39be9420c4
test: add coverage for ParallelMap and ParallelFilter workers
Add tests to verify default worker behavior in ParallelMap and
ParallelFilter.
Add internal test to cover unexported Result marker methods for
coverage.
2025-09-01 22:54:03 -04:00
9cf61ec6c5
feat: add ParallelFilter and UniqueInPlace functions
Add `ParallelFilter` for concurrent filtering with context and error
support.
Add `UniqueInPlace` to remove duplicates from slices in place. Update
README
and add documentation and tests for both functions.
2025-09-01 18:16:59 -04:00
1031038d42
feat: add Chunk, ContainsBy, UniqueBy, ParallelMap, map helpers
- Add `Chunk` to split slices into groups of size n.
- Add `ContainsBy` for predicate-based containment checks.
- Add `UniqueBy` to deduplicate slices by key selector.
- Add `ParallelMap` for concurrent mapping with context and error
handling.
- Add `maps.Keys` and `maps.Values` helpers for extracting map
keys/values.
- Update README and docs for new features.
- Refactor `Contains` to use `slices.Contains`.
2025-09-01 18:03:38 -04:00
Daniel Smith
8c78743f1a
[CHORE] bump docker golang version and dependencies (#40) 2025-07-14 17:13:22 +02:00
fbf58eff42
Refresh documentation (#39)
* minor documentation fixes

* fix Hugo warnings

* add openssf badge
2024-12-03 09:29:53 +01:00
Carlos A Saavedra
fbbd0398c9
adding support for quick pointer conversion (#38)
* adding support for quick pointer convertion

* function comment update
2024-11-01 10:24:53 +01:00
Carlos A Saavedra
acf26bbaf9
Adding support for Slice sorting (Asc & Desc) (#37)
* creating slice and pointer changes

* removing extra file

* switching to use 'sliceStable'
2024-11-01 10:18:33 +01:00
539f8c518a
update codecov action version 2024-11-01 10:13:44 +01:00
507e604582
update actions to .23 2024-09-08 20:32:12 +02:00
88dce52921
add dockerfile to build doc 2024-09-08 20:12:47 +02:00
e0fe93efaa
update to go 1.23 2024-09-08 19:39:27 +02:00
78b90acc67
reformat readme 2024-09-08 19:14:07 +02:00
eda818c6e0
format docs 2024-09-08 19:11:52 +02:00
Andy Long
bfac048fb4
Updating Count function (#36)
* Adding some new funky functions which I find useful

Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions

Created the Join, JoinProjection, Range, SumMap, Zip functions, ecah fuction is documented with how it works and had a unit test or maybe more

* Added in an OrderBy function

* Documentation comment for OrderBy which I missed out

* Adding a Unit test for JoinProject function

Updated the comments on the Join & OrderBy functions so they make a little more sense.

Covered an extra test case with the Join test, where the left set has more data than the right and so the Right handside array of the join is empty

* Adding a count method to the package, so you can find out how many items in a slice satisfy and given condition

* Updating count to work with any so you can count structs as well as basic types

* Removing extra underscores
2023-06-13 14:21:56 +02:00
541e707861
Update unit-test.yml 2023-06-07 15:11:21 +02:00
d5426ad3cb Merge branch 'main' of https://github.com/rjNemo/underscore 2023-06-07 14:58:40 +02:00
64fcfee748 update go version 2023-06-07 14:55:06 +02:00
054679fb18 add group by to docs 2023-06-07 14:49:55 +02:00
Andy Long
291df4fe4e
Adding a Count function (#34)
* Adding some new funky functions which I find useful

Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions

Created the Join, JoinProjection, Range, SumMap, Zip functions, ecah fuction is documented with how it works and had a unit test or maybe more

* Added in an OrderBy function

* Documentation comment for OrderBy which I missed out

* Adding a Unit test for JoinProject function

Updated the comments on the Join & OrderBy functions so they make a little more sense.

Covered an extra test case with the Join test, where the left set has more data than the right and so the Right handside array of the join is empty

* Adding a count method to the package, so you can find out how many items in a slice satisfy and given condition
2022-11-30 13:34:01 +01:00
Andy Long
0bc3a54efd
Adding some new funky functions (#32)
* Adding some new funky functions which I find useful

Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions

Created the Join, JoinProjection, Range, SumMap, Zip functions, ecah fuction is documented with how it works and had a unit test or maybe more

* Added in an OrderBy function

* Documentation comment for OrderBy which I missed out

* Adding a Unit test for JoinProject function

Updated the comments on the Join & OrderBy functions so they make a little more sense.

Covered an extra test case with the Join test, where the left set has more data than the right and so the Right handside array of the join is empty
2022-09-04 09:21:31 +02:00
Ruidy
4042208482
add flatmap (#31)
* add flatmap

Signed-off-by: Ruidy <ruidy.nemausat@gmail.com>

* add to readme

Signed-off-by: Ruidy <ruidy.nemausat@gmail.com>

Signed-off-by: Ruidy <ruidy.nemausat@gmail.com>
Co-authored-by: Ruidy <ruidy.nemausat@gmail.com>
2022-08-10 17:01:43 +02:00
Ruidy
8c2f92f202
ternary op function (#29)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-06-08 09:14:03 +02:00
Ruidy
d1da6fbab0 update installing info 2022-05-07 12:52:06 -04:00
Ruidy
e5b3ad8ef1
add groupBy function (#28) 2022-04-20 22:23:59 +02:00
Ruidy
7fef1562f2
unique function (#27)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-04-12 23:32:13 +02:00
Ruidy
f6af583408
Pipe (#26)
* rename to pipe

* add security scan

* use var in Makefile
2022-03-31 17:37:02 +02:00
Ruidy
1166c701ac
add intersection (#25)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-27 06:34:09 +02:00
Ruidy
6a1a4c157b update docs 2022-03-25 11:00:09 -04:00
Ruidy
d9c1c152ba
update docs (#24)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-25 10:39:45 -04:00
Ruidy
6b377350d6
U 21 diff (#23)
* add logo and fix project image description

* add difference function

* update docs

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-24 17:30:01 +01:00
Ruidy
eebeb65114
add logo and fix project image description (#22)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-24 17:03:10 +01:00
Ruidy
235b36b7f6 add documentation link 2022-03-23 10:58:44 -04:00
Ruidy
d19fa7b8c9
docsite (#19)
* change documentation theme and structure

* add config files

* fix links

* add build doc command

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-23 10:32:56 -04:00
Ruidy
c00d9af59f
drop (#18)
* last function

* drop function

* add documentation

* fix CI

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-21 18:04:38 +01:00
Ruidy
fb517f3b04
last function (#17)
* last function

* fix CI

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-21 18:04:30 +01:00
Ruidy
edb3c09e43 update badges 2022-03-18 13:37:24 -04:00
Ruidy
e156992382
Add Result type (#16)
* 👷 adding test and push coverage

* ⬆️ use official Go 1.18 image

*  result interface

* delete commented code

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-18 18:32:41 +01:00
Ruidy
3bfe1aca18
Code coverage (#15)
* 👷 adding test and push coverage

* ⬆️ use official Go 1.18 image

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-18 18:22:01 +01:00
Ruidy
bbb199ce62
clean_builds (#14)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-18 18:16:38 +01:00
Ruidy
482e553263
sum (#13)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-02-20 15:34:09 +01:00
Ruidy
28f85bdc94
use comparable constraint in contains (#12)
Co-authored-by: Ruidy <ruidy.nemausat@gmail.com>
2022-02-12 21:08:46 +01:00
Ruidy
7d422c59d3
each (#10)
* feat: maps map

* : return initial slice

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-01-28 12:51:42 -04:00
Ruidy
f73905ddb0
feat: maps map (#9)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-01-27 16:15:33 +01:00
Ruidy
c0a8ecea0c chore: use alpine distro for leaner container 2022-01-07 06:29:14 -04:00
Ruidy
c9e54a11cb chore: remove codecov 2022-01-05 12:43:35 -04:00