Skip to content

Commit

Permalink
Build new doc
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed Nov 21, 2022
1 parent 7deeab4 commit ecf306d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions doc/Psalm.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- [N-combinators](#N-combinators)
- [proveTrue](#proveTrue)
- [toEither](#toEither)
- [partitionT](#partitionT)
- [filterNotNull](#filterNotNull)

# Static analysis

Expand Down Expand Up @@ -349,3 +351,49 @@ $ vendor/bin/psalm-plugin enable fp4php/functional
return $separated->toEither();
}
```

- #### partitionT

Plugin infers each `list` type from predicates of `partitionT`:

``` php
<?php

declare(strict_types=1);

use Tests\Mock\Foo;
use Tests\Mock\Bar;
use Tests\Mock\Baz;

use function Fp\Collection\partitionT;

/**
* @param list<Foo|Bar|Baz> $list
* @return array{list<Foo>, list<Bar>, list<Baz>}
*/
function testExhaustiveInference(array $list): array
{
return partitionT($list, fn($i) => $i instanceof Foo, fn($i) => $i instanceof Bar);
}
```

- #### filterNotNull

Plugin turns all nullable keys to possibly undefined keys:

``` php
<?php

declare(strict_types=1);

use function Fp\Collection\filterNotNull;

/**
* @param array{name: string, age: int|null} $shape
* @return array{name: string, age?: int}
*/
function example(array $shape): array
{
return filterNotNull($shape);
}
```

0 comments on commit ecf306d

Please sign in to comment.