Add pointer methods#24
Merged
markphelps merged 8 commits intomarkphelps:masterfrom Jul 7, 2023
Merged
Conversation
* Support “null”
This change adds support for marshaling and unmarshaling “null” and reflecting that the value is not present, rather than relying on the “zero” value
* Fix to specify {{ .VariableName }}
* Add support for go modules
* Fix go mod path
* Update golden test
* Remove go.mod per pull request
markphelps
reviewed
Jun 29, 2023
| return {{ .OutputName }}{&v} | ||
| } | ||
|
|
||
| // New{{ .OutputName }}FromPointer creates an optional.{{ .OutputName }} from a {{ .TypeName }} pointer. |
Owner
There was a problem hiding this comment.
Better late than never ;)
WDYT about FromPtr / ToPtr ? saves some keystrokes and I think is just as readable?
Contributor
Author
There was a problem hiding this comment.
I like it. I’ll push up and update
markphelps
approved these changes
Jul 6, 2023
Owner
markphelps
left a comment
There was a problem hiding this comment.
Lgtm! Thank you. Will create a new release in the morning
Contributor
Author
@markphelps any chance we could deploy today? I'd love to update our code to use this :) |
Owner
|
@mwielbut thanks again for the contribution!! I just created https://github.com/markphelps/optional/releases/tag/v0.11.0 with the change I'm going to be paying more attention to this library going forward and hope to do more regular releases. Thanks again! |
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.
This PR adds some convenience methods to make it easier to convert between pointer and Optional representation of values.
Using the Optional package inevitably leads to lots of code like this when we need to convert back to pointers:
or the other way:
Two new functions are introduced, one to create an Optional given a pointer, and the other to return the embedded value as a pointer. Note, in both cases the value is copied over, the pointer is never passed directly as that would break the encapsulation.
With the two methods, the above examples become simple one-line statements: