Skip to main content

struct

OptionalReg

A register-passable optional type.

This struct optionally contains a value. It only works with trivial register passable types at the moment.

Parameters

  • T (AnyRegType): The type of value stored in the Optional.

Implemented traits

AnyType, Boolable

Methods

__init__

__init__(inout self: Self, /)

Create an optional with a value of None.

__init__(value: T) -> Self

Create an optional with a value.

Args:

  • value (T): The value.

Returns:

The optional.

__init__(value: None) -> Self

Create an optional without a value from a None literal.

Args:

  • value (None): The None value.

Returns:

The optional without a value.

__bool__

__bool__(self: Self) -> Bool

Return true if the optional has a value.

Returns:

True if the optional has a valu and False otherwise.

__invert__

__invert__(self: Self) -> Bool

Return False if the optional has a value.

Returns:

False if the optional has a value and True otherwise.

__is__

__is__(self: Self, other: None) -> Bool

Return True if the Optional has no value.

It allows you to use the following syntax: if my_optional is None:

Args:

  • other (None): The value to compare to (None).

Returns:

True if the Optional has no value and False otherwise.

__isnot__

__isnot__(self: Self, other: None) -> Bool

Return True if the Optional has a value.

It allows you to use the following syntax: if my_optional is not None:

Args:

  • other (None): The value to compare to (None).

Returns:

True if the Optional has a value and False otherwise.

__and__

__and__[type: Boolable](self: Self, other: type) -> Bool

Return true if self has a value and the other value is coercible to True.

Parameters:

  • type (Boolable): Type coercible to Bool.

Args:

  • other (type): Value to compare to.

Returns:

True if both inputs are True after boolean coercion.

__or__

__or__[type: Boolable](self: Self, other: type) -> Bool

Return true if self has a value or the other value is coercible to True.

Parameters:

  • type (Boolable): Type coercible to Bool.

Args:

  • other (type): Value to compare to.

Returns:

True if either inputs is True after boolean coercion.

__rand__

__rand__[type: Boolable](self: Self, other: type) -> Bool

Return true if self has a value and the other value is coercible to True.

Parameters:

  • type (Boolable): Type coercible to Bool.

Args:

  • other (type): Value to compare to.

Returns:

True if both inputs are True after boolean coercion.

__ror__

__ror__[type: Boolable](self: Self, other: type) -> Bool

Return true if self has a value or the other value is coercible to True.

Parameters:

  • type (Boolable): Type coercible to Bool.

Args:

  • other (type): Value to compare to.

Returns:

True if either inputs is True after boolean coercion.

value

value(self: Self) -> T

Get the optional value.

Returns:

The contained value.