linkedliststack not longer requires T to be comparable #288

Open
oliverdain wants to merge 1 commit from oliverdain/simple-list into master
oliverdain commented 2025-09-03 01:51:12 +00:00 (Migrated from github.com)

I had a use case for a stack with a type that's not comparable. I noticed that none of the methods on linkedliststack.Stack actually requires T to be comparable. It seems the requirement stems from the fact that linkedliststack is based on singlylinkedlist which has 3 methods (IndexOf, Contains, and Sort) which Stack doesn't use.

This refactors singlylinkedlist.List into a singlylinkedlist.SimpleList which has a T any generic type. And then singlylinkedlist.List embeds SimpleList and adds those 3 methods. Then Stack is based on a SimpleList[T any] and it no longer requires comparable.

If you like the general approach here I suspect you'd want additional changes like an interface for simple lists, maybe all stacks no longer require comparable, etc. I wanted to get some early feedback to see if you're on board with this direction and, if so, where you'd want to take this.

I had a use case for a stack with a type that's not comparable. I noticed that none of the methods on `linkedliststack.Stack` actually requires `T` to be comparable. It seems the requirement stems from the fact that `linkedliststack` is based on `singlylinkedlist` which has 3 methods (`IndexOf`, `Contains`, and `Sort`) which `Stack` doesn't use. This refactors `singlylinkedlist.List` into a `singlylinkedlist.SimpleList` which has a `T any` generic type. And then `singlylinkedlist.List` embeds `SimpleList` and adds those 3 methods. Then `Stack` is based on a `SimpleList[T any]` and it no longer requires comparable. If you like the general approach here I suspect you'd want additional changes like an interface for simple lists, maybe all stacks no longer require comparable, etc. I wanted to get some early feedback to see if you're on board with this direction and, if so, where you'd want to take this.
sonarqubecloud[bot] commented 2025-09-03 01:51:35 +00:00 (Migrated from github.com)
## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=gods&pullRequest=288) **Quality Gate passed** Issues ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=gods&pullRequest=288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=gods&pullRequest=288&issueStatuses=ACCEPTED) Measures ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=gods&pullRequest=288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=gods&pullRequest=288&metric=new_coverage&view=list) ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=gods&pullRequest=288&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=gods&pullRequest=288)
This pull request has changes conflicting with the target branch.
  • lists/singlylinkedlist/singlylinkedlist.go
  • stacks/linkedliststack/linkedliststack.go
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin "oliverdain/simple-list:oliverdain/simple-list"
git switch "oliverdain/simple-list"

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch "master"
git merge --no-ff "oliverdain/simple-list"
git switch "oliverdain/simple-list"
git rebase "master"
git switch "master"
git merge --ff-only "oliverdain/simple-list"
git switch "oliverdain/simple-list"
git rebase "master"
git switch "master"
git merge --no-ff "oliverdain/simple-list"
git switch "master"
git merge --squash "oliverdain/simple-list"
git switch "master"
git merge --ff-only "oliverdain/simple-list"
git switch "master"
git merge "oliverdain/simple-list"
git push origin "master"
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods!288
No description provided.