diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5f51e5e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +tests export-ignore +Dockerfile export-ignore +bin export-ignore +.github export-ignore +.molireali export-ignore diff --git a/README.md b/README.md index f137446..1575aab 100644 --- a/README.md +++ b/README.md @@ -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 $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 diff --git a/tests/ReadmeTest.php b/tests/ReadmeTest.php index 65126c5..e2b7811 100644 --- a/tests/ReadmeTest.php +++ b/tests/ReadmeTest.php @@ -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' => '', ]; }