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
Say, I would like to sort a []Person w.r.t Age somewhere in my app, and w.r.t. Name at some other place in my app. I dont even want to dictate a member name "Key" to the user of my Sort() function. So I want to:
contract orderedMember(S, M) {
ordered(S.M)
}
// or
contract orderedMember(S, M, T) {
ordered(T)
S.M T
}
this contract means "type S has a member M that is ordered". So that could be used like:
func Sort(type S orderedMember) (x []S){
...
if x[i].M < x[j].M { // use M in code
...
}
var x []Person
...
Sort(M=Age) (x)
Sort(M=Name) (x)
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
Proposal: Go 2: Extend contracts to include member variables
proposal: Go 2: extend contracts to include member variables
Aug 1, 2019
Contracts proposal includes only member functions.
this means "type T shall have a method named String that returns string". A natural extension could be like:
sortable contract means "type S shall have a member named Key that is int". A better extension could be:
sortable2 contract means "type S shall have a member named Key that is ordered". This contract could be used like:
Also I think this syntax is better for methods and members:
A further extension could be like:
Say, I would like to sort a []Person w.r.t Age somewhere in my app, and w.r.t. Name at some other place in my app. I dont even want to dictate a member name "Key" to the user of my Sort() function. So I want to:
this contract means "type S has a member M that is ordered". So that could be used like:
The text was updated successfully, but these errors were encountered: