feat: add group functions#12
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release Notes
Go 1.24 Functional Helpers Update
This release updates
gofnfor Go 1.24 and expands the library with helpers focused on working with large slices of records in a cleaner, functional style.Highlights
slices,cmp, andmath/rand/v2.forandifblocks.GroupBynow stores the grouped rows instead of returning empty groups.New Array Helpers
The
arraypackage now includes:GroupSumBy: group rows by a key and sum a numeric value.GroupSumByWhere: filter, group, and sum in a single pass.GroupCountBy: count rows by key.GroupReduceBy: build custom aggregate summaries by key.GroupStatsBy: calculate count, sum, min, max, and average by key.DistinctBy: keep the first row for each key.IndexBy: create a map by key, keeping the last row for duplicate keys.Partition: split a slice into matching and non-matching rows.SortBy: sort by a selected ordered field without mutating the original slice.Take: return the firstnrows.Skip: skip the firstnrows.Chunk: split rows into batches.Chaining Support
The
array.Array[T]chain API now includes practical methods for common record workflows:GroupSumByGroupSumByWhereGroupCountByGroupStatsByDistinctByIndexByPartitionSortByStringSortByFloat64TakeSkipChunkBecause Go does not currently support method-specific type parameters, some chained helpers use practical fixed key/value types. For fully generic keys and numeric value types, use the package-level functions.
Pipe Support
The
pipepackage now includes adapters for the new helpers:GroupSumByGroupSumByWhereGroupCountByGroupReduceByGroupStatsByDistinctByIndexByPartitionSortByTakeSkipChunkExample
For custom summaries:
Compatibility
The existing public APIs remain available. The changes are intended to preserve the current usage style while adding new helpers and improving correctness.
One behavioral fix to note:
GroupBynow returns populated groups. Previous behavior created the group keys but did not append the matching rows.Verification
The release was validated with:
go test -count=1 ./... go vet ./...Local coverage after these changes is
88.7%.