News for hackers. Stuff that matters.
Re:Practical Go: Real-world advice for writing maintainable ... by vorg on Thursday February 21, 2019 @07:17PM (#19221931)
You could use a struct with private fields, e.g.

  type Users struct{
    dict map[string]*User
    list []*User
  }
and attach methods to both access the data and coordinatedly update both forms, e.g.

  func (us *Users) byID(id string) *User { ... }
  func (us *Users) sortedByID() []*User { ... }
  func (us *Users) addUser(id string, nu *User) {
    dict[id] = nu
    list = append(list, nu)
    ...
  }

There are no comments on this comment yet.