mutable: fix wrong/misleading doc comments on Filter, FilterI, Map, MapI#888
Open
c-tonneslan wants to merge 1 commit into
Open
mutable: fix wrong/misleading doc comments on Filter, FilterI, Map, MapI#888c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
A few things in mutable/slice.go don't match the code: - Filter's doc says the predicate takes "an element of the slice and its index". It doesn't, only FilterI does. That belongs on FilterI. - Map's doc says "The function returns the modified slice, which has the same length as the original". It doesn't return anything. Same for MapI. - Filter's "modifies the input slice in-place to contain only the elements that satisfy the predicate" is true of the returned slice header but not of the caller's original variable, which keeps its original length and may have leftover duplicates past the kept prefix. That's exactly what tripped the reporter in samber#842. Rewrite the comments to say what each function actually does and to spell out the leftover-tail gotcha on Filter. No code change. For samber#842 Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
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.
For #842.
A few of the doc comments in
mutable/slice.godon't match what the code does:Filter's doc says the predicate takes "an element of the slice and its index". It doesn't, onlyFilterIdoes.MapandMapIclaim "The function returns the modified slice, which has the same length as the original". Neither one returns anything.Filter's "modifies the input slice in-place to contain only the elements that satisfy the predicate" is true of the returned slice header, but not of the caller's original variable, which keeps its original length and the tail is leftover from before the call (often duplicates of the last kept element). That's the surprise the reporter hit:[{foo} {baz} {baz}]instead of[{foo} {baz}].Rewrote the comments to say what each function actually does and to spell out the leftover-tail behavior on
Filter. No code change, so no new tests.