Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Backtrack auto-unwrapping, unless it ignores arguments (scalar return…
… value).
  • Loading branch information
loganhenson committed Oct 25, 2019
commit 8c4d37cb31d3f1f4c7ea9c8241b06abee9c1ad67
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $addSix(4); // 10;
Pattern Matching.
```php
Pattern::match([
fn(Just $value) => $unwrapped,
fn(Just $value) => fn ($unwrapped) => $unwrapped,
fn(Nothing $value) => 'nothing',
])(Maybe::just('just')); // 'just'
```
Expand All @@ -60,7 +60,7 @@ $errorHandler = function (Err $err) {
};

return Pattern::match([
fn(Ok $value) => $user,
fn(Ok $value) => fn (User $user) => $user,
$errorHandler
])(Result::from(fn() => User::findOrFail(1)));
```
8 changes: 4 additions & 4 deletions tests/Control/PatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function it_matches_on_type()
public function it_can_match_on_result_ok()
{
$match = Pattern::match([
fn (Ok $value) => fn (int $value) => $value + 2,
fn (Ok $value) => fn (string $value) => $value . 'bc',
fn (Err $error) => 'nothing',
]);

$this->assertEquals(3, $match(Result::ok(1)));
$this->assertEquals('abc', $match(Result::ok('a')));
}

/** @test */
Expand All @@ -71,11 +71,11 @@ public function it_can_match_on_result_err()
public function it_can_match_on_maybe_just()
{
$match = Pattern::match([
fn (Just $value) => $value + 2,
fn (Just $value) => fn (string $value) => $value . 'bc',
fn (Nothing $_) => 'nothing',
]);

$this->assertEquals(3, $match(Maybe::just(1)));
$this->assertEquals('abc', $match(Maybe::just('a')));
}

/** @test */
Expand Down