-
Notifications
You must be signed in to change notification settings - Fork 76
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
Use ^7.1 php with iterables #52
Conversation
src/iter.php
Outdated
@@ -295,15 +286,14 @@ function reductions(callable $function, $iterable, $startValue = null) { | |||
* iter\zip([1, 2, 3], [4, 5, 6], [7, 8, 9]) | |||
* => iter([1, 4, 7], [2, 5, 8], [3, 6, 9]) | |||
* | |||
* @param array|Traversable ...$iterables Iterables to zip | |||
* @param iterable[] ...$iterables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be just iterable ...$iterables
? That's the syntax PHP uses.
src/iter.php
Outdated
* | ||
* @return \Iterator | ||
* @return iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether we should guarantee that the return value is Iterator
, rather than any iterable
. That would make the laziness of these functions (somewhat) part of the signature contract.
src/iter.php
Outdated
@@ -869,11 +837,11 @@ function join($separator, $iterable) { | |||
* iter\count(iter\flatten([1, 2, 3, [4, [[[5, 6], 7]]], 8])) | |||
* => 8 | |||
* | |||
* @param array|Traversable|\Countable $iterable The iterable to count | |||
* @param iterable|array|Traversable|\Countable $iterable The iterable to count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array and Traversable can be dropped here, as they are covered by the iterable now.
Done |
* | ||
* @return \Iterator | ||
*/ | ||
function map(callable $function, $iterable) { | ||
_assertIterable($iterable, 'Second argument'); | ||
function map(callable $function, iterable $iterable): iterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @return
annotation and the "actual" return type are different now, should also be \Iterable
in the return type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\Iterable
or just iterable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Urgh sorry, that was a typo, I was referring to \Iterator
there.
src/iter.php
Outdated
@@ -514,7 +497,7 @@ function drop($num, $iterable) { | |||
* | |||
* @return \Iterator | |||
*/ | |||
function repeat($value, $num = INF) { | |||
function repeat($value, int $num = INF): iterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://3v4l.org/cgnkk this is going to throw an Error when called without the second argument. Looks like there is no test for that case, so this didn't turn up in CI :(
src/iter.php
Outdated
function slice($iterable, $start, $length = INF) { | ||
_assertIterable($iterable, 'First argument'); | ||
|
||
function slice(iterable $iterable, $start, $length = INF): iterable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $start
here can also be int
(though $length
can't be).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it use PHP_INT_MAX instead?
I'm a bit confused about the right return types in phpdoc blocks. Should it be |
The right return type is one of |
@nikic fixed |
Merged as c40a7ec, thanks! |
No description provided.