Skip to content

Commit

Permalink
Merge pull request #21 from petrknap/chores
Browse files Browse the repository at this point in the history
chore: updated examples and added `.gitattributes`
  • Loading branch information
petrknap authored May 25, 2024
2 parents e16fd4e + 89bc2e9 commit 72eedab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests export-ignore
Dockerfile export-ignore
bin export-ignore
.github export-ignore
.molireali export-ignore
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@ It is an easy way to make sure that everyone has to check if they have (not) rec
```php
namespace PetrKnap\Optional;

$optionalString = Optional::of('value');

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

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

if ($optionalString->equals('value')) {
echo 'It is `value`.';
/** @var Optional<string> $optionalString */
$optionalString = Optional::of('data');
if ($optionalString->isPresent()) {
echo $optionalString->get();
}

echo $optionalString->map(fn ($s) => "`{$s}`")->orElse('empty');
echo $optionalString->flatMap(fn ($s) => Optional::of("`{$s}`"))->orElse('empty');
OptionalResource::ofFalsable(tmpfile())->ifPresent(function ($tmpFile): void {
fwrite($tmpFile, 'data');
fclose($tmpFile);
});
```

### Create and use your own typed optional
Expand Down
11 changes: 1 addition & 10 deletions tests/ReadmeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ public static function getPathToMarkdownFile(): string
public static function getExpectedOutputsOfPhpExamples(): iterable
{
return [
'examples' => ''
. 'value'
. 'value'
. 'value'
. 'value'
. 'value'
. 'It is `value`.'
. '`value`'
. '`value`'
,
'examples' => 'data',
'create-and-use-your-own-typed-optional' => '',
];
}
Expand Down

0 comments on commit 72eedab

Please sign in to comment.