Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F49450629
Option.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
Option.php
View Options
<?php
namespace
Keruald\OmniTools\DataTypes\Option
;
abstract
class
Option
{
public
abstract
function
isSome
()
:
bool
;
public
abstract
function
isNone
()
:
bool
;
public
abstract
function
getValue
()
:
mixed
;
public
abstract
function
map
(
callable
$callable
)
:
self
;
/**
* Returns the option if it contains a value,
* otherwise returns the default option.
*/
public
abstract
function
or
(
Option
$default
)
:
self
;
/**
* Returns the option if it contains a value,
* otherwise calls the callable and returns the result.
*
* The callable is called only on None, allowing lazy evaluation.
* The callable must return an Option.
*/
public
abstract
function
orElse
(
callable
$callable
)
:
self
;
/**
* Returns the value of the option if it is Some,
* or the default value if the option is None.
*
* @param mixed $default The default value
* @return mixed
*/
public
abstract
function
getValueOr
(
mixed
$default
)
:
mixed
;
/**
* Returns the value of the option if it is Some,
* or the result of the callable if the option is None.
*
* The callable is called only on None, allowing lazy evaluation.
*
* @param callable $callable A function that returns a default value.
* @return mixed
*/
public
abstract
function
getValueOrElse
(
callable
$callable
)
:
mixed
;
///
/// Helper to build options
///
/**
* Converts a nullable value to an Option.
*
* @param mixed $value
*
* @return Option An instance of None if the value is null; otherwise, an instance of Some.
*/
public
static
function
from
(
mixed
$value
)
:
self
{
return
match
(
$value
)
{
null
=>
new
None
,
default
=>
new
Some
(
$value
),
};
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Sep 14, 08:47 (15 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4062388
Default Alt Text
Option.php (1 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment