File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ $addSix(4); // 10;
3939Pattern Matching.
4040``` php
4141Pattern::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
6262return 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```
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments