nullable

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nullable provides a generic value with an explicit null state. It does not implement JSON, BSON, or SQL encoding interfaces.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Null

type Null[T any] struct {
	// contains filtered or unexported fields
}

Null is a generic type that represents a nullable value. There are 2 possible states:

  • Null: > value: zero value of T > valid: false

  • Not Null: > value: value of T > valid: true

func None

func None[T any]() Null[T]

Constructors None returns a Null[T] with valid set to false.

func Some

func Some[T any](value T) Null[T]

Some returns a Null[T] with valid set to true.

Example
package main

import (
	"fmt"

	"github.com/cohesian-tools/typy/opt/nullable"
)

func main() {
	value := nullable.Some(0)
	missing := nullable.None[int]()
	fmt.Println(value.IsNull(), value.Unwrap())
	fmt.Println(missing.IsNull())
}
Output:
false 0
true

func (Null[T]) IsNull

func (n Null[T]) IsNull() bool

Methods - Inspection IsNull returns true if the Null is in a Null state.

func (Null[T]) Unwrap

func (n Null[T]) Unwrap() T

- Fetching Unwrap returns the inner value of a Not Null. If the Null is in a Null state, Unwrap panics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL