Skip to content

Commit 8c4d37c

Browse files
committed
Backtrack auto-unwrapping, unless it ignores arguments (scalar return value).
1 parent 15dd036 commit 8c4d37c

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $addSix(4); // 10;
3939
Pattern Matching.
4040
```php
4141
Pattern::match([
42-
fn(Just $value) => $unwrapped,
42+
fn(Just $value) => fn ($unwrapped) => $unwrapped,
4343
fn(Nothing $value) => 'nothing',
4444
])(Maybe::just('just')); // 'just'
4545
```
@@ -60,7 +60,7 @@ $errorHandler = function (Err $err) {
6060
};
6161

6262
return Pattern::match([
63-
fn(Ok $value) => $user,
63+
fn(Ok $value) => fn (User $user) => $user,
6464
$errorHandler
6565
])(Result::from(fn() => User::findOrFail(1)));
6666
```

tests/Control/PatternTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public function it_matches_on_type()
4949
public function it_can_match_on_result_ok()
5050
{
5151
$match = Pattern::match([
52-
fn (Ok $value) => fn (int $value) => $value + 2,
52+
fn (Ok $value) => fn (string $value) => $value . 'bc',
5353
fn (Err $error) => 'nothing',
5454
]);
5555

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

5959
/** @test */
@@ -71,11 +71,11 @@ public function it_can_match_on_result_err()
7171
public function it_can_match_on_maybe_just()
7272
{
7373
$match = Pattern::match([
74-
fn (Just $value) => $value + 2,
74+
fn (Just $value) => fn (string $value) => $value . 'bc',
7575
fn (Nothing $_) => 'nothing',
7676
]);
7777

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

8181
/** @test */

0 commit comments

Comments
 (0)