-
-
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
Fix inits
operation
#191
Fix inits
operation
#191
Conversation
@@ -24,26 +24,26 @@ final class Inits extends AbstractOperation | |||
/** | |||
* @pure | |||
* | |||
* @return Closure(Iterator<TKey, T>): Generator<int, list<T>> | |||
* @return Closure(Iterator<TKey, T>): Generator<int, list<array{0: TKey, 1: T}>> |
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.
can we not use Unpack
to keep the previous behaviour?
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 unfortunately not possible because each items is converted to an array of items.
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.
Unless using generators in place of arrays... But I don't find that very user friendly at all.
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.
Could you add an example in the docs of how a user could get the same result as previously?
E.g.
Collection::fromIterable(range('a', 'c'))
->inits()
->....()
// to get this -> [ ['a'], ['a', 'b'], ['a', 'b', 'c'] ]
Job done. I updated the documentation examples. |
->inits() | ||
->map(static fn (array $data): array => array_column($data, 1)); |
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.
We could add another equivalent one:
Collection::fromIterable($input)
->inits()
->pluck('*.1');
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.
Will add 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.
I added it 😉
Since this pull request has not had any activity within the last 5 days, I have marked it as stale. |
@drupol please feel free to merge this once the checks have finished 😁 |
Thanks @AlexandruGG :) |
This PR:
Inits
operation, it works with any type of keys now.