diff --git a/src/combinators.php b/src/combinators.php index fb3b480..f61ae17 100644 --- a/src/combinators.php +++ b/src/combinators.php @@ -392,18 +392,36 @@ function repeat(int $n, Parser $parser): Parser * * @template T * + * $psalm-param positive-int $n * @psalm-param Parser $parser * - * @psalm-return Parser + * @psalm-return Parser> * @api */ function repeatList(int $n, Parser $parser): Parser { - $parser = map($parser, /** @psalm-param mixed $output */ fn($output): array => [$output]); + /** @palm-var Parser> $parser */ + $parser = map( + $parser, + /** + * @psalm-param T $output + * @psalm-return list + */ + fn($output): array => [$output] + ); $parsers = array_fill(0, $n - 1, $parser); + return foldl( $parsers, + /** + * @psalm-param Parser> $l + * @psalm-param Parser> $r + * @psalm-return Parser> + * + * @psalm-suppress InvalidReturnType + * @psalm-suppress InvalidReturnStatement + */ fn(Parser $l, Parser $r): Parser => append($l, $r), $parser )->label("$n times " . $parser->getLabel());