Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12944231
Some.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
Some.php
View Options
<?php
namespace
Keruald\OmniTools\DataTypes\Option
;
use
InvalidArgumentException
;
use
Keruald\OmniTools\Reflection\Type
;
class
Some
extends
Option
{
private
mixed
$value
=
null
;
private
string
$type
=
"NULL"
;
public
function
__construct
(
$value
=
null
)
{
if
(
$value
!==
null
)
{
$this
->
setValue
(
$value
);
}
}
public
function
isSome
()
:
bool
{
return
true
;
}
public
function
isNone
()
:
bool
{
return
false
;
}
public
function
getValue
()
:
mixed
{
return
$this
->
value
;
}
public
function
setValue
(
mixed
$value
)
:
void
{
$type
=
Type
::
getTypeOf
(
$value
);
if
(!
$this
->
isAcceptableValueType
(
$type
))
{
throw
new
InvalidArgumentException
(
<<<'EOD'
When you mutate the value of an Some object, you can't mutate the object type.
Please consider return a new Some instead.
EOD
);
}
$this
->
value
=
$value
;
$this
->
type
=
$type
;
}
private
function
isAcceptableValueType
(
string
$type
)
:
bool
{
return
$this
->
value
===
null
||
$type
===
$this
->
type
;
}
public
function
map
(
callable
$callable
)
:
Option
{
$value
=
$callable
(
$this
->
value
);
return
new
self
(
$value
);
}
public
function
orElse
(
mixed
$default
)
:
mixed
{
return
$this
->
value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Nov 18, 17:09 (21 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3136417
Default Alt Text
Some.php (1 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment