-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add new manipulation and analyze methods for collections. #44
Add new manipulation and analyze methods for collections. #44
Conversation
This will add the following methods: columns, first, last, sort, filter, where, map, diff, intersect, unique, merge
Added a phpstan.neon to be able to validate prophecy calls.
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.
Overall I love it.
I would remove the unique
as we still have some discussion about that one, and also increase why comments on some of the code and tests, but then I'm happy :)
Will update after I got my little girl to sleep ;) |
Would using array_values instead of merging it with an empty array work?
The array_merge with the extra array is a little confusing to read, and I
wonder about performance?
…On Fri, Oct 5, 2018, 11:48 AM Andreas Frömer ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/AbstractCollection.php
<#44 (comment)>:
> + $temp[] = $this->extractValue($item, $propertyOrMethod);
+ }
+
+ return $temp;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function first()
+ {
+ if (empty($this->data)) {
+ throw new OutOfBoundsException('Can\'t determine first item. Collection is empty');
+ }
+
+ $temp = array_merge([], $this->data);
Because of the nature of array_shift and array_pop which will alter the
target array. This will make sure I will lose the reference of the current
data array.
And because the key of the data list is not necessary numeric I just use
internal function to get the last or first item.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#44 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEAm5lH_ohfG1XCVjKMBskEXkTLODjxaks5uh39ngaJpZM4XC_Mg>
.
|
Yep. I just changed it to use the internal array pointer with |
This will now used the internal array pointer instead of copying the whole collection. This should improve the performance
Remove unique() method for now, as the definition of "uniqueness" is still under discussion
This should cover all possible outcomes of the ValueExtractorTrait
This will separate the tests for manipulating a collection from the default operations. This should make sure everyone knows what these tests are doing and why they are doing what they do ;)
This will call some internal functions from root namespace to benefit from opcode optimization
@jmauerhan as you requested changes, can you give it another look? |
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 think the one exception name should be changed but otherwise good. @ramsey ?
@jmauerhan renamed the exception. |
Awesome. Thank you 😊 |
🎉 |
Solve #13.
This will add the following methods:
The methods have been implemented according to the suggested API. If you want any change to these methods. Keep me posted.