Skip to content

Improve reduce() signature to exclude null from return type when non-null initial value is passed #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$ of callable callable\\(TResult, TValue\\)\\: TResult expects TResult, TResult\\|null given\\.$#"
count: 1
path: src/iterable-functions.php

-
message: "#^Function BenTools\\\\IterableFunctions\\\\iterable_reduce\\(\\) should return TResult but returns TResult\\|null\\.$#"
count: 1
path: src/iterable-functions.php

3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ parameters:
- '~Method BenTools\\IterableFunctions\\IterableObject::map\(\) should return BenTools\\IterableFunctions\\IterableObject<TKey, TResult> but returns BenTools\\IterableFunctions\\IterableObject<int\|string, TResult>~'

- '~Function BenTools\\IterableFunctions\\iterable_map\(\) should return iterable<TKey, TResult> but returns array<TResult>\|BenTools\\IterableFunctions\\IterableObject<TKey, TResult>~'

includes:
- phpstan-baseline.neon
6 changes: 3 additions & 3 deletions src/iterable-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ function iterable_filter(iterable $iterable, ?callable $filter = null): iterable
* Reduces an iterable.
*
* @param iterable<TValue> $iterable
* @param callable(TResult|null, TValue):TResult $reduce
* @param TResult|null $initial
* @param TResult $initial
* @param callable(TResult, TValue):TResult $reduce
*
* @return TResult|null
* @return TResult
*
* @template TValue
* @template TResult
Expand Down