-
-
Notifications
You must be signed in to change notification settings - Fork 942
Add two function EqualPtr and ComparePtr #790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uginroot
wants to merge
5
commits into
samber:master
Choose a base branch
from
uginroot:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92ac402
feat: add EqualPtr function to compare pointer values
uginroot 085cc88
feat: add ComparePtr function to compare pointer values
uginroot 254fba8
fix: update source references in core type documentation
uginroot 2e36b68
fix: update ComparePtr function to use constraints.Ordered type
uginroot 23cc4af
fix: update source references in core type documentation
uginroot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| name: ComparePtr | ||
| slug: compareptr | ||
| sourceRef: type_manipulation.go#L228 | ||
| category: core | ||
| subCategory: type | ||
| signatures: | ||
| - "func ComparePtr[T cmp.Ordered](a, b *T) bool" | ||
| variantHelpers: | ||
| - core#type#compareptr | ||
| similarHelpers: | ||
| - core#type#equalptr | ||
| - core#type#fromptr | ||
| - core#type#toptr | ||
| position: 110 | ||
| --- | ||
|
|
||
| ComparePtr compares two pointers and returns: | ||
| - 0 if both are nil or *a == *b | ||
| - -1 if a is nil (and b is not) or *a < *b | ||
| - 1 if b is nil (and a is not) or *a > *b | ||
|
|
||
| Nil is treated as less than any non-nil value. | ||
|
|
||
| ```go | ||
| ptr42 := lo.ToPtr(42) | ||
| ptr42_2 := lo.ToPtr(42) | ||
| ptr100 := lo.ToPtr(100) | ||
| ptrNil := (*int)(nil) | ||
|
|
||
| equal1 := lo.ComparePtr(ptr42, ptr42_2) | ||
| // equal1: 0 (42 == 42) | ||
|
|
||
| equal2 := lo.ComparePtr(ptr42, ptr100) | ||
| // equal2: -1 (42 < 100) | ||
|
|
||
| equal3 := lo.ComparePtr(ptr100, ptr42) | ||
| // equal3: 1 (100 > 42) | ||
|
|
||
| equal4 := lo.ComparePtr(ptr42, ptrNil) | ||
| // equal4: 1 (42 > nil) | ||
|
|
||
| equal5 := lo.ComparePtr(ptrNil, ptr42) | ||
| // equal5: -1 (nil < 42) | ||
|
|
||
| equal6 := lo.ComparePtr(ptrNil, ptrNil) | ||
| // equal6: 0 (nil == nil) | ||
| ``` |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| name: EqualPtr | ||
| slug: equalptr | ||
| sourceRef: type_manipulation.go#L219 | ||
| category: core | ||
| subCategory: type | ||
| signatures: | ||
| - "func EqualPtr[T comparable](a, b *T) bool" | ||
| variantHelpers: | ||
| - core#type#equalptr | ||
| similarHelpers: | ||
| - core#type#compareptr | ||
| - core#type#fromptr | ||
| - core#type#toptr | ||
| position: 100 | ||
| --- | ||
|
|
||
| Compares two pointers: returns true if both are nil or both point to equal values, false if only one is nil or values differ. | ||
|
|
||
| ```go | ||
| ptr42 := lo.ToPtr(42) | ||
| ptr42_2 := lo.ToPtr(42) | ||
| ptr100 := lo.ToPtr(100) | ||
| ptrNil := (*int)(nil) | ||
|
|
||
| equal1 := lo.EqualPtr(ptr42, ptr42_2) | ||
| // equal1: true (both point to 42) | ||
|
|
||
| equal2 := lo.EqualPtr(ptr42, ptr100) | ||
| // equal2: false (42 != 100) | ||
|
|
||
| equal3 := lo.EqualPtr(ptr42, ptrNil) | ||
| // equal3: false (one is nil) | ||
|
|
||
| equal4 := lo.EqualPtr(ptrNil, ptrNil) | ||
| // equal4: true (both are nil) | ||
| ``` |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.