Record TOptional
Unit
Declaration
type TOptional<T> = record
Description
A generic record that holds an optional (nullable) value of type T
.
This type is inspired by Java's Optional
type and is useful for indicating the presence or absence of a value, avoiding the need for sentinel values like 0 or empty string for non-nullable types.
Overview
Methods
![]() |
class function From(Value: T): TOptional<T>; static; |
![]() |
class function Empty: TOptional<T>; static; |
![]() |
function Get: T; |
![]() |
function TryGet(out Value: T): Boolean; |
![]() |
function OrElse(Default: T): T; |
![]() |
function OrElseGet(Supplier: TFunc<T>): T; |
![]() |
procedure IfPresent(Consumer: TProc<T>); |
![]() |
class operator Implicit(Value: T): TOptional<T>; inline; |
Properties
![]() |
property IsPresent: Boolean read FIsPresent; |
![]() |
property IsEmpty: Boolean read GetIsEmpty; |
Description
Methods
![]() |
class function From(Value: T): TOptional<T>; static; |
Creates an instance of
Parameters
ReturnsA |
![]() |
class function Empty: TOptional<T>; static; |
Creates an empty ReturnsA |
![]() |
function Get: T; |
Returns the held value if it is present, otherwise raises an EOptionalError if the optional is empty.
ReturnsThe held value Exceptions raised
|
![]() |
procedure IfPresent(Consumer: TProc<T>); |
Executes the provided consumer procedure if the value is present. Parameters
|
![]() |
class operator Implicit(Value: T): TOptional<T>; inline; |
Implicit conversion operator to allow assigning a value of type
Parameters
ReturnsA |
Properties
![]() |
property IsPresent: Boolean read FIsPresent; |
Indicates whether the value is present. |
![]() |
property IsEmpty: Boolean read GetIsEmpty; |
Indicates whether the optional is empty. |
Generated by PasDoc 0.16.0-snapshot.