Skip to content

Commit ecf306d

Browse files
committed
Build new doc
1 parent 7deeab4 commit ecf306d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

doc/Psalm.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- [N-combinators](#N-combinators)
1212
- [proveTrue](#proveTrue)
1313
- [toEither](#toEither)
14+
- [partitionT](#partitionT)
15+
- [filterNotNull](#filterNotNull)
1416

1517
# Static analysis
1618

@@ -349,3 +351,49 @@ $ vendor/bin/psalm-plugin enable fp4php/functional
349351
return $separated->toEither();
350352
}
351353
```
354+
355+
- #### partitionT
356+
357+
Plugin infers each `list` type from predicates of `partitionT`:
358+
359+
``` php
360+
<?php
361+
362+
declare(strict_types=1);
363+
364+
use Tests\Mock\Foo;
365+
use Tests\Mock\Bar;
366+
use Tests\Mock\Baz;
367+
368+
use function Fp\Collection\partitionT;
369+
370+
/**
371+
* @param list<Foo|Bar|Baz> $list
372+
* @return array{list<Foo>, list<Bar>, list<Baz>}
373+
*/
374+
function testExhaustiveInference(array $list): array
375+
{
376+
return partitionT($list, fn($i) => $i instanceof Foo, fn($i) => $i instanceof Bar);
377+
}
378+
```
379+
380+
- #### filterNotNull
381+
382+
Plugin turns all nullable keys to possibly undefined keys:
383+
384+
``` php
385+
<?php
386+
387+
declare(strict_types=1);
388+
389+
use function Fp\Collection\filterNotNull;
390+
391+
/**
392+
* @param array{name: string, age: int|null} $shape
393+
* @return array{name: string, age?: int}
394+
*/
395+
function example(array $shape): array
396+
{
397+
return filterNotNull($shape);
398+
}
399+
```

0 commit comments

Comments
 (0)