"zero value" keyword
In Rust none is the default value. Since golang automatically zero intializes all values it would be nice to check if a value is zero initialized
it would be nice to check if a value is zero initialized Do you mean compare to zero value? you can always do this:
func isZero[T any](v T) bool {
var zero T
return v == zero
}
right? or do you refer to other use cases?
Can you provide an example of usage of none?
it would be nice to check if a value is zero initialized Do you mean compare to zero value? you can always do this:
func isZero[T any](v T) bool { var zero T return v == zero }right? or do you refer to other use cases? Can you provide an example of usage of
none?
@avivcarmis Hey, sorry I took so long to reply. Thanks so much for the open mindedness of your reply.
Basically:
var err error
if err == none {
log.Println("no error");
}
I'm not sure about this one, i'll explain why: you should always be able to tell the zero value of things without the none value.
In a non-generic case (like the one you provided here ^) the zero value is clear from the type. In this case it will be nil - the zero value of error.
In a generic case you can always write/use the isZero func I added above.
Given the this operator does really open up any new capabilities and adds a bit of fragmentation (there will always be more than one way to test for zero values), I'm not sure about it.