Skip to content
/ typ Public

Clean type handling for the Go programming language with undefinable and nullable generic types.

License

Notifications You must be signed in to change notification settings

inkognitro/typ

Repository files navigation

typ

Imagine a *string type: Does this type correspond to a nullable or an undefinable string?

Insecurities about types like the one above are eliminated by using the types of this package. Distinction between undefined, null and concrete values is as important as handling the same data types equally, over the whole application.

Build your own Undefinable[Foo], Nullable[Foo] or even UndefinableNullable[Foo] type with the provided generic types of this package. Even union types are supported by using the AnyOf[AnyOfRuler] generic type.

Example:

import (
	"fmt"
	"github.com/inkognitro/typ"
)

id1 := typ.NewUuidV4()
id2 := typ.UndefinableUuid{}

// Try to convert an undefinable value to a defined one:
if _, ok := id2.ToUuid(); !ok {
    fmt.Println("could not convert id2 to uuid, because the underlying value is undefined")
}

// Comparison between two values:
if id1.ToUndefinableUuid().Equals(id2) {
    fmt.Println("what the heck is going on here")
}

About

Clean type handling for the Go programming language with undefinable and nullable generic types.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages