Closed MarkKremer closed 4 years ago
I'm trying to compare nullable types but I couldn't find an existing easy way to do it.
Are you interested in adding support for / accepting a PR that adds functions like the following for all nulltypes?
func StringEquals(a, b null.String) bool { return a.Valid == b.Valid && (! a.Valid || a.String == b.String) } // StringEquals(null.NewString("foo", false), null.NewString("foo", false)) -> true // StringEquals(null.NewString("foo", false), null.NewString("bar", false)) -> true // StringEquals(null.NewString("foo", true), null.NewString("foo", false)) -> false // StringEquals(null.NewString("foo", true), null.NewString("foo", true)) -> true // StringEquals(null.NewString("foo", true), null.NewString("bar", true)) -> false
I'm not entirely sure about the workings of the zerotypes (I don't use them). If I got it right, they can just be compared using their string/bool/int/... value so they don't need the extra function, right?
Good idea! How about we add an Equals() method to every type? Might be cleaner than adding new free functions.
Equals()
Merged in #36.
I'm trying to compare nullable types but I couldn't find an existing easy way to do it.
Are you interested in adding support for / accepting a PR that adds functions like the following for all nulltypes?
I'm not entirely sure about the workings of the zerotypes (I don't use them). If I got it right, they can just be compared using their string/bool/int/... value so they don't need the extra function, right?