Add bind() to option and result
This commit is contained in:
@@ -85,6 +85,30 @@ class OptionTest extends TestCase
|
||||
$this->assertEquals('passed', $value, 'The value should have been obtained from the option');
|
||||
}
|
||||
|
||||
#[TestDox('Bind succeeds with None')]
|
||||
public function testBindSucceedsWithNone(): void
|
||||
{
|
||||
$original = Option::None();
|
||||
$bound = $original->bind(fn($it) => Option::Some('value'));
|
||||
$this->assertTrue($bound->isNone(), 'The option should have been None');
|
||||
$this->assertSame($original, $bound, 'The same None instance should have been returned');
|
||||
}
|
||||
|
||||
#[TestDox('Bind succeeds with Some and Some')]
|
||||
public function testBindSucceedsWithSomeAndSome(): void
|
||||
{
|
||||
$bound = Option::Some('hello')->bind(fn($it) => Option::Some('goodbye'));
|
||||
$this->assertTrue($bound->isSome(), 'The option should have been Some');
|
||||
$this->assertEquals('goodbye', $bound->get(), 'The bound function was not called');
|
||||
}
|
||||
|
||||
#[TestDox('Bind succeeds with Some and None')]
|
||||
public function testBindSucceedsWithSomeAndNone(): void
|
||||
{
|
||||
$bound = Option::Some('greetings')->bind(fn($it) => Option::None());
|
||||
$this->assertTrue($bound->isNone(), 'The option should have been None');
|
||||
}
|
||||
|
||||
#[TestDox('Map succeeds with None')]
|
||||
public function testMapSucceedsWithNone(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user