Skip to content

Commit

Permalink
chore: updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
petrknap committed May 11, 2024
1 parent b70f2db commit 1c37072
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ It is an easy way to make sure that everyone has to check if they have (not) rec
namespace PetrKnap\Optional;

/** @var Optinal<string> $optionalString */
$optionalString = new Optional('value');
$optionalString = Optional::of('value');

echo $optionalString->isPresent() ? $optionalString->get() : 'empty';
echo $optionalString->orElse('empty');
echo $optionalString->orElseGet(fn () => 'empty');
echo $optionalString->orElseThrow(fn () => new \Exception());

$optionalString->ifPresent(function (string $value): void { echo $value; });

Expand Down
2 changes: 2 additions & 0 deletions tests/ReadmeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static function getExpectedOutputsOfPhpExamples(): iterable
{
return [
'example' => ''
. 'value'
. 'value'
. 'value'
. 'value'
. 'value'
Expand Down

0 comments on commit 1c37072

Please sign in to comment.