-
-
Notifications
You must be signed in to change notification settings - Fork 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
Update various typing information #196
Changes from 8 commits
3ae485a
e2ef673
673f3ee
b722eb9
40ce120
2f81bce
dafa9b6
b4cdd4a
b449188
0b8d1de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
use loophp\collection\Collection; | ||
|
||
include __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
// Example 1: Both callbacks are provided | ||
$input = range(1, 5); | ||
|
||
Collection::fromIterable($input) | ||
->associate( | ||
static function ($key, $value) { | ||
return $key * 2; | ||
}, | ||
static function ($value, $key) { | ||
return $value * 3; | ||
} | ||
); | ||
|
||
// [ | ||
// 0 => 3, | ||
// 2 => 6, | ||
// 4 => 9, | ||
// 6 => 12, | ||
// 8 => 15, | ||
// ] | ||
|
||
// Example 2: Only the callback for keys is provided | ||
$input = range(1, 5); | ||
|
||
Collection::fromIterable($input) | ||
->associate( | ||
static function ($key, $value) { | ||
return $key * 2; | ||
} | ||
); | ||
|
||
// [ | ||
// 0 => 1, | ||
// 2 => 2, | ||
// 4 => 3, | ||
// 6 => 4, | ||
// 8 => 5, | ||
// ] | ||
|
||
// Example 3: Only the callback for values is provided | ||
$input = range(1, 5); | ||
|
||
Collection::fromIterable($input) | ||
->associate( | ||
null, | ||
static function ($value, $key) { | ||
return $value * 3; | ||
} | ||
); | ||
|
||
// [ | ||
// 0 => 3, | ||
// 1 => 6, | ||
// 2 => 9, | ||
// 3 => 12, | ||
// 4 => 15, | ||
// ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,12 @@ interface Zipable | |
* | ||
* @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#zip | ||
* | ||
* @param iterable<mixed, mixed> ...$iterables | ||
* @template U | ||
* @template UKey | ||
* | ||
* @return Collection<list<mixed>, list<mixed>> | ||
* @param iterable<UKey, U> ...$iterables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that it's not possible to type this thing as it is a variadic parameter. I don't know if it's a good idea, but I had the idea to do the typing of only one element, knowing that it would not be completely valid if there are more than one parameters given. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get what you're looking to do here. The only issue is that when a user will try to use it with multiple iterables of different types they will get an error and so think that it's not supposed to be used like that. I'm not sure how people normally use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I leave this question open as I don't have any idea yet on what is best to do... |
||
* | ||
* @return Collection<list<TKey|UKey>, list<T|U>> | ||
*/ | ||
public function zip(iterable ...$iterables): Collection; | ||
} |
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.
This is the only part (The 2 new entries in this file) that I cannot fix. If you have any idea, just let me know.
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.
it's a bit difficult to tell at a glance, but leave this will me I will try to see if I can figure out the problem and fix it
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.
Ok, thanks! :)
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.
@drupol so after testing I realised this happens when passing a callable which takes multiple parameters, both to the ClosureIterator and the Collection object itself. Why? I'm not entirely sure but see the latest commit and the other comment for the changes I did and let me know if you think that works