Skip to content

Conversation

@muir
Copy link
Collaborator

@muir muir commented Apr 29, 2025

The Values function is obvious.
CombineSlices now all can have no arguments, though in that case, the generic binding must be provided explicitly.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new map helper function (Values) and refactors the CombineSlices function to allow being called with no arguments while enhancing its test coverage.

  • Updates the CombineSlices function to accept variadic slice inputs and adjust its logic accordingly.
  • Introduces additional tests in slice_test.go for various input scenarios for CombineSlices.
  • Adds a new Values function in map.go to retrieve map values.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
slice_test.go Updates tests for CombineSlices with additional and refined cases.
slice.go Refactors CombineSlices to support no arguments and to avoid unnecessary copies.
map_test.go Removes extraneous semicolons for stylistic consistency.
map.go Adds a new Values function to extract map values.
Comments suppressed due to low confidence (1)

slice.go:83

  • [nitpick] Consider renaming the parameter 'more' to 'slices' to more clearly indicate that all provided slices are being combined. This might aid readability for new callers.
func CombineSlices[T any](more ...[]T) []T {

@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b41b45d) to head (9194463).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #10   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          169       172    +3     
=========================================
+ Hits           169       172    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@muir muir changed the title add map Values function; allow CombineSlices to take no args [feat] add map Values function; allow CombineSlices to take no args (BREAKING CHANGE) Apr 29, 2025
@muir muir requested a review from Copilot April 29, 2025 00:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Values function for maps and updates the CombineSlices function to allow no arguments (with explicit generic binding required).

  • Adds unit tests for the new Values function in map_test.go
  • Refactors CombineSlices in slice.go and updates its tests in slice_test.go to cover multiple edge cases, including nil returns and optimizations
  • Minor stylistic adjustments in test cases

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
slice_test.go Updated tests for CombineSlices with additional edge case scenarios
slice.go Refactored CombineSlices to support variadic slice inputs and optimizations
map_test.go New test cases for the Values function and minor style adjustments
map.go Added implementation for the Values function
Comments suppressed due to low confidence (2)

slice.go:83

  • [nitpick] Consider renaming the variadic parameter 'more' to 'slices' or similar to better convey that it represents all input slices.
func CombineSlices[T any](more ...[]T) []T {

map.go:11

  • [nitpick] Consider adding a function comment for Values to document its behavior, similar to the documentation provided for the Keys function.
func Values[K comparable, V any](m map[K]V) []V {

@muir muir force-pushed the values branch 2 times, most recently from 6208f9e to 08bea92 Compare April 29, 2025 00:33
@muir muir requested a review from Copilot April 29, 2025 00:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new map utility function, Values, and refactors CombineSlices to accept a variadic number of slices (including no slices), with the latter being a breaking change.

  • Introduces a new Values function in map.go along with comprehensive tests in map_test.go.
  • Updates CombineSlices in slice.go to support zero or one generic slice input, and adjusts the associated tests in slice_test.go accordingly.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
slice_test.go Updated test cases for CombineSlices, covering various input cases
slice.go Refactored CombineSlices to accept variadic slices with breaking change
map_test.go Added tests ensuring correct behavior of the new Values function
map.go Implemented the new Values function for map utilities

slice.go Outdated
if total == len(first) {
return first
if total == len(slices[0]) {
return slices[0]
Copy link

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the original slice when no additional slices contribute elements may lead to unintended side effects if the caller later mutates the result. Consider documenting this behavioral nuance or copying the slice to enforce immutability.

Suggested change
return slices[0]
return CopySlice(slices[0])

Copilot uses AI. Check for mistakes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, looking at the tests this seems to be expected, but maybe worth documenting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a CombineSlicesCopy that always copies. Documented.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces two main features: a new map Values function to extract values from a map, and updates to the CombineSlices functionality to allow a call with no arguments (with an explicit generic binding required in that scenario).

  • Added Values function and associated tests in map.go and map_test.go.
  • Refactored CombineSlices and added CombineSlicesCopy in slice.go, along with comprehensive tests in slice_test.go to verify various slice combination behaviors.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
slice_test.go Updated tests for CombineSlices and added tests for CombineSlicesCopy behavior
slice.go Modified CombineSlices to accept variadic slices and added CombineSlicesCopy
map_test.go Added tests for the new Values function
map.go Added simple implementation of the Values function

slice.go Outdated
Comment on lines 81 to 92
// CombineSlices may return the first slice if it is the only slice with elements. A copy
// is only made if it has to be made.
func CombineSlices[T any](first []T, more ...[]T) []T {
if len(more) == 0 {
return first
}
if len(first) == 0 && len(more) == 1 {
return more[0]
// is only made if it has to be made. For no input, nil is returned.
func CombineSlices[T any](slices ...[]T) []T {
switch len(slices) {
case 0:
return nil
case 1:
return slices[0]
case 2:
if len(slices[0]) == 0 {
return slices[1]
}
Copy link

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The special handling for exactly two slices—returning the second slice when the first is empty—may lead to inconsistent behavior compared to cases with more slices. Consider evaluating if this optimization should be extended or clearly documented to avoid confusion.

Copilot uses AI. Check for mistakes.

slice.go Outdated
return CombineSlicesCopy[T](slices...)
}

// CombineSlicesCopy combines all of it's input slices, always
Copy link

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using 'its' instead of 'it's' in the comment for grammatical correctness.

Suggested change
// CombineSlicesCopy combines all of it's input slices, always
// CombineSlicesCopy combines all of its input slices, always

Copilot uses AI. Check for mistakes.

@muir muir merged commit beb0095 into main Apr 29, 2025
29 checks passed
@muir muir deleted the values branch April 29, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants