swift - Can I automatically derive some instances like Equatable? -
say have struct memebers equatable
.
struct s { let : string let b : int let c : double }
would know of way automatically make s
equatable without manually , boringly defining ==
?
no, you'll have define manually:
func == (l: s, r: s) -> bool { return l.a == r.a && l.b == r.b && l.c == r.c }
that's short can make it. it's pretty darn short (one line!), meaning clear, , it's ready future complications may add type. happy!
Comments
Post a Comment