gonull icon indicating copy to clipboard operation
gonull copied to clipboard

Add a comparison method that will compare Nullibles by value.

Open benjaminlgur opened this issue 11 months ago • 1 comments

For example

func NullIsEqual[T comparable](a gonull.Nullable[T], b gonull.Nullable[T]) bool {
	// If both are not present, they are considered equal
	if !a.Present && !b.Present {
		return true
	}
	// If both are present and values are equal, they are considered equal
	return a.Present && b.Present && a.Val == b.Val
}

func NewNull[T comparable](value T) gonull.Nullable[T] {
	return gonull.Nullable[T](gonull.NewNullable(value))
}

benjaminlgur avatar Mar 06 '24 22:03 benjaminlgur