Skip to content

Null

Bases: OptionType[T]

Option variant representing the absence of a value.

This class or NONE can be used interchangeably, as calling Null() will always return the singleton instance NONE.

For pattern matching, you must use Null, as NONE isn't special cased by type checkers the same way python None is, and thus can't be narrowed to Null.

Example:

>>> from pyochain import Null, NONE, Some
>>> Null() is NONE
True
>>> def is_none(x: Option[int]) -> bool:
...     match x:
...         case Null():
...             return True
...         case Some(_):
...             return False
>>> is_none(NONE)
True
>>> is_none(Some(42))
False
>>> is_none(Null())
True
For more documentation, see the Option[T] class.