-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Either and Maybe ::memoize() not loading everything
- Loading branch information
Showing
5 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
use Innmind\Immutable\Either; | ||
use Innmind\BlackBox\Set; | ||
|
||
return static function() { | ||
yield proof( | ||
'Either::memoize() any composition', | ||
given(Set\Type::any()->filter(static fn($value) => !\is_null($value))), | ||
static function($assert, $value) { | ||
$loaded = false; | ||
$either = Either::defer(static fn() => Either::right($value)) | ||
->flatMap(static function() use ($value, &$loaded) { | ||
return Either::defer(static function() use ($value, &$loaded) { | ||
$loaded = true; | ||
|
||
return Either::right($value); | ||
}); | ||
}); | ||
|
||
$assert->false($loaded); | ||
$either->memoize(); | ||
$assert->true($loaded); | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters