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
Presently in go, there is auto typing available on function returns. value := MyFunc(). It would follow that given a known type on a function eg func SomeThing(options Options) that passing a structure that meets the type description required by the function should allow you to avoid presenting the full type name.
If you assign a struct/slice to a variable you would need to present a type.
value:= { Name: "John Smith" } // Not allowed, since it's ambigious
Since having the ability to call functions with similar syntax {} values. The alternative would be to flag it as an anonymous struct or array by adding a struct{ .... } which still allows for the caller to quickly write compatible calls for interfaces without having to add fully qualified type descriptors.
funcmain() {
SomeThing(struct{Name: "John Smith"})
AnotherThing([]{"one", "two"}) // potentially simillary matched with an anon array
}
Cons:
The biggest loss is that you no longer have the explicit type name in the call to the function.
The text was updated successfully, but these errors were encountered:
Summary:
Allow for anonymous types for struct and array be passed to functions.
Motivation:
Presently in go, there is auto typing available on function returns.
value := MyFunc()
. It would follow that given a known type on a function egfunc SomeThing(options Options)
that passing a structure that meets the type description required by the function should allow you to avoid presenting the full type name.If you assign a struct/slice to a variable you would need to present a type.
Generally trying to avoid having to write:
Alternative:
Since having the ability to call functions with similar syntax
{}
values. The alternative would be to flag it as an anonymous struct or array by adding astruct{ .... }
which still allows for the caller to quickly write compatible calls for interfaces without having to add fully qualified type descriptors.Cons:
The biggest loss is that you no longer have the explicit type name in the call to the function.
The text was updated successfully, but these errors were encountered: