Skip to content

Releases: nicheinc/nullable

v2.1.0: ApplyPtr and DiffPtr

25 Aug 19:29
b70bdfc
Compare
Choose a tag to compare

This release adds ApplyPtr and DiffPtr methods to Update[T] via #12.

v2.0.0: Generic Update Types

15 Jun 15:40
20c4b70
Compare
Choose a tag to compare

Version 2 Features

Version 2 replaces the Nullable interface and various implementations
(including user-defined implementations!) with just two generic types:
Update[T] and SliceUpdate[T].

Update uses a value internally, rather than a pointer. This may reduce the
need for allocations, and it also means that updates can now be meaningfully
compared using ==.

In nullable version 1, only nullable.String implements fmt.Stringer. With
go 1.18 generics, it's not possible to implement an interface only for
particular type parameters of a generic type, leaving us with the choice to
implement fmt.Stringer for all types or for none. We chose the former. The
Update implementation uses a type switch to check if T is itself a string
or fmt.Stringer, falling back to fmt.Sprintf with the %v verb for all
other types. (The SliceUpdate[T] implementation always uses fmt.Sprintf with
%v since a []T is not string or fmt.Stringer.)

Migration Guide

The package has been renamed from nullable to nup (for "nullable update").
It's 62.5% shorter and 87% more whimsical! You should replace v1 imports
(github.com/nicheinc/nullable) with github.com/nicheinc/nullable/v2/nup.

The old Value method on each Nullable type has been replaced with three
Update/SliceUpdatge methods: Value, ValueOperation, and ValueOrNil:

  • The new Value method returns two values: value and isSet. isSet
    indicates whether the update is a set operation. If isSet is true, then
    value is the update's set value. If isSet is false, then value is the
    zero value for the update's type parameter.
  • ValueOperation is similar to the new Value method but returns value and
    operation. value is the zero value unless operation == OpSet. This
    method is useful for handling all three update types in one switch statement,
    for example.
  • ValueOrNil behaves similarly to the old Value methods, returning a value
    pointer that is non-nil only if the update is a set operation. However,
    unlike the old methods, the returned pointer references a fresh copy of the
    contained value, so it can't be used to mutate the update.

The following table illustrates some of the other noteworthy differences between
version 1 and 2:

Version 1 Version 2
nullable.Int nup.Update[int]
nullable.NewIntPtr(p) nup.RemoveOrSet(p)
u.IsSet() u.IsChange()
u.Removed() u.IsRemove()
u.Equals(5) u.IsSetTo(5)
u.IsNegative() u.IsSetSuchThat(func(v int) bool { return v < 0 })

The semantics of IsSet() have changed from the version 1 types. Previously,
IsSet() returned true if the update was a set or removal update. In version
2, a given update is exactly one of three operations: no-op, remove, or set.
Thus IsSet() is now mutually exclusive to IsRemove (Removed(), in version
1). Suppose you had a variable update of type nullable.Int, and you used
update.IsSet() to check that update is not the zero value. Then you should
not only change update's type to nup.Update[int] because IsSet() will no
longer return true if update is a remove operation. You should instead use
update.IsChange().

The following update-type-specific value checks have been removed: Int.IsZero,
Int.IsNegative, Float64.IsZero, Float64.IsNegative, String.IsEmpty, and
StringSlice.IsEmpty. If go generics are ever extended to support type
constraints on generic methods, we could restore some of these methods. For now,
use IsSetTo or IsSetSuchThat with a suitable argument (as shown in the table
above). Another option is to implement the removed type-specific methods you
care about as free functions, for instance:

func IsNegative(update nup.Update[int]) bool {
	value, ok := update.Value()
	return ok && value < 0
}

Clean up golint warnings and remove coverage badge

10 Dec 17:21
f8a2fcb
Compare
Choose a tag to compare
Merge pull request #8 from nicheinc/enhancement/golint-cleanup

Clean up golint warnings and remove coverage badge

Open-source under the MIT license

02 Dec 20:46
fa31ef6
Compare
Choose a tag to compare
Merge pull request #7 from nicheinc/feature/open-source

Open-source the library

v1.3.0 Equals, Apply, Apply, Diff

22 Oct 21:15
623ad72
Compare
Choose a tag to compare

Add Equals, Apply, ApplyPtr, and Diff methods to each type.

Export the InterfaceValue method

01 Oct 21:01
4530844
Compare
Choose a tag to compare
Merge pull request #3 from nicheinc/bug/i2

Export the InterfaceValue method

Stringy Strings

10 Sep 16:59
090258f
Compare
Choose a tag to compare

nullable.String now implements Stringer.

Version 1.0.0

05 Aug 20:14
7cc466d
Compare
Choose a tag to compare

This package has now been QA'd via its use in both entity and search so should be ready for v1.0.0.

v0.1.0

19 Apr 22:18
Compare
Choose a tag to compare
v0.1.0 Pre-release
Pre-release
Support marshalling non-structs

v0.0.0

19 Apr 20:37
Compare
Choose a tag to compare
v0.0.0 Pre-release
Pre-release
Remove partial doc string