We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I often map some structs with pointers (intended to express optional values) into Option types.
Example:
type A { X *int Y *string } type B { X Option[int] Y Option[string] }
I can easily map pointer typed value into Option values:
var a A ... b := B{ X: optional.FromNillable(a.X), Y: optional.FromNillable(b.Y), }
However, in the opposite case, I have to add some boilerplate code:
var b B ... var x *int B.X.IfSome(func(value int) { x = &value }) var y *int B.Y.IfSome(func(value string) { y = &value }) a := A{X: x, Y: y}
I believe this process could be simplified with a symmetric handler for FromNillable. (i.e. ToNillable)
func (o Option[T]) ToNillable() *T var b B ... a := A{ X: b.X.ToNillable(), Y: b.Y.ToNillable(), }
Thank you for your hard work on this library!
The text was updated successfully, but these errors were encountered:
Support UnwrapAsPtr() method to unwrap the Option value as a pointer
UnwrapAsPtr()
b455687
Fix #25 Signed-off-by: moznion <[email protected]>
Hi @gwolves, thank you for your suggestion! I just implemented UnwrapAsPtr() method at #28 so I'll be happy if this would work for you.
Sorry, something went wrong.
I published v0.11.0 which contains this change.
moznion
Successfully merging a pull request may close this issue.
I often map some structs with pointers (intended to express optional values) into Option types.
Example:
I can easily map pointer typed value into Option values:
However, in the opposite case, I have to add some boilerplate code:
I believe this process could be simplified with a symmetric handler for FromNillable. (i.e. ToNillable)
Thank you for your hard work on this library!
The text was updated successfully, but these errors were encountered: