Repository navigation
feature(stack): add TryPop and TryPeek methods - #60
Merged
Merged
Conversation
Owner
|
Please fix the formatting issue and add a test that covers the case where 0 is pushed and then popped with |
mohitjoshi-hey
force-pushed
the
feat/stack-try-methods
branch
from
October 12, 2026 04:48
a8e379a to
1380da1
Compare
Contributor
Author
|
I added those missing test cases covering TryPeek and TryPop when 0 is pushed/popped. And also formatted the files with gofmt |
Owner
|
Thanks, please resolve the conflicts (caused by merging the other PR), and then I will merge. |
Contributor
Author
|
I hope this helps. Thanks!! |
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.
Description
This PR addresses the ambiguity in stack operations when the stack is empty and the returned value happens to be the zero value of the generic type.
Changes
TryPop() (T, bool)to return the top element and indicate whether the operation succeeded.TryPeek() (T, bool)to retrieve the top element without removing it and indicate whether the operation succeeded.Testing
go test ./stack/....Closes #59