Skip to content

Commit 697b17a

Browse files
committed
Add proveNull function
1 parent 14aa163 commit 697b17a

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"src/Fp/Functions/Collection/Tail.php",
8787
"src/Fp/Functions/Collection/Zip.php",
8888
"src/Fp/Functions/Collection/MkString.php",
89+
"src/Fp/Functions/Evidence/ProveNull.php",
8990
"src/Fp/Functions/Evidence/ProveArray.php",
9091
"src/Fp/Functions/Evidence/ProveBool.php",
9192
"src/Fp/Functions/Evidence/ProveFloat.php",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Fp\Evidence;
6+
7+
use Fp\Functional\Option\Option;
8+
9+
/**
10+
* Prove that subject is null.
11+
*
12+
* ```php
13+
* >>> proveNull(null);
14+
* => Some(null)
15+
*
16+
* >>> proveNull(1);
17+
* => None
18+
* ```
19+
*
20+
* @return Option<null>
21+
*/
22+
function proveNull(mixed $potential): Option
23+
{
24+
return null === $potential ? Option::some($potential) : Option::none();
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Runtime\Functions\Evidence;
6+
7+
use Fp\Functional\Option\Option;
8+
use PHPUnit\Framework\TestCase;
9+
10+
use function Fp\Evidence\proveNull;
11+
12+
final class ProveNullTest extends TestCase
13+
{
14+
public function testProveNull(): void
15+
{
16+
$this->assertEquals(Option::none(), proveNull(1));
17+
$this->assertEquals(Option::some(null), proveNull(null));
18+
}
19+
}

0 commit comments

Comments
 (0)