You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We got used to it, that we need for all of the scenarios above to know which type it is, although it is sometimes quite annoying although it might be clear what kind of value we need at this point (due to the fact that Go is that type safe).
But once we start with Generics it is getting tricky. Assuming the following example:
...extend this functionality with another token to all meaningful contexts. I would purpose the - sign here, because I would assume it will not break old code, with not clash with future use and might be quite intuitive, like:
It might also improve the checking for emptiness after we retrieved a value from a method, because here we can use the same token again, in all cases if something is empty, like:
ifreturnFloat64==- {
// [..]
}
ifreturnSlice==- { // in case of slice it should match `nil` and `len(x) == 0`// [..]
}
ifreturnMap==- { // in case of map it should match `nil` and `len(x) == 0`// [..]
}
ifreturnAStruct==- { // same as `returnAStruct == AStruct{}`// [..]
}
ifreturnAnInterface==- { // same as `returnAnInterface == nil`// [..]
}
// ..
The text was updated successfully, but these errors were encountered:
Background
Currently there are a couple of different empty values, like:
Assuming now you have a functions like this...
Problem
We got used to it, that we need for all of the scenarios above to know which type it is, although it is sometimes quite annoying although it might be clear what kind of value we need at this point (due to the fact that Go is that type safe).
But once we start with Generics it is getting tricky. Assuming the following example:
In this case you cannot simply return a value. There is a workaround, but it is not quite handy in all scenarios:
Proposal
As the compiler is currently already doing some context related assumptions, like:
...extend this functionality with another token to all meaningful contexts. I would purpose the
-
sign here, because I would assume it will not break old code, with not clash with future use and might be quite intuitive, like:Consequently this will solve our Generics problem the following way:
Additional benefit
It might also improve the checking for emptiness after we retrieved a value from a method, because here we can use the same token again, in all cases if something is empty, like:
The text was updated successfully, but these errors were encountered: