Skip to content
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

Feature: Add Squash operation #83

Merged
merged 9 commits into from
May 16, 2021
Merged

Feature: Add Squash operation #83

merged 9 commits into from
May 16, 2021

Conversation

drupol
Copy link
Collaborator

@drupol drupol commented May 15, 2021

This PR

  • Add Squash operation
  • Has relevant interfaces
  • Has tests
  • Has documentation

Follows #82.
Related to #80.
Fixes #80.

This was referenced May 15, 2021
@drupol drupol force-pushed the feat-add-squash-operation branch from 2424ef3 to a10e2ab Compare May 15, 2021 15:54
@drupol
Copy link
Collaborator Author

drupol commented May 15, 2021

Ready for another review.

@drupol drupol added the enhancement New feature or request label May 16, 2021
@drupol drupol self-assigned this May 16, 2021
@@ -712,6 +712,11 @@ public function split(int $type = Operation\Splitable::BEFORE, callable ...$call
return new self(Split::of()($type)(...$callbacks), $this->getIterator());
}

public function squash(): CollectionInterface
{
return self::fromIterable($this->pack()->all())->unpack();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need I can help adding the docs for this method, but would just like to understand a bit better how this works. I'm looking at the docs for pack and unpack but still don't get why they're needed here 😓.

If you don't mind can you explain what's the difference between this and doing the below?

return self::fromIterable($this->all());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it has to do with the collections allowing keys that are not only int|string as well as duplicate keys, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. iterator_to_array() will fail if keys are different from int|string.

See: https://3v4l.org/FW0Ca

@drupol drupol marked this pull request as ready for review May 16, 2021 08:19
@drupol
Copy link
Collaborator Author

drupol commented May 16, 2021

Ready for the last review!

@drupol drupol force-pushed the feat-add-squash-operation branch from 1141c77 to 80659f7 Compare May 16, 2021 09:06
@drupol drupol force-pushed the feat-add-squash-operation branch from 80659f7 to 34020ae Compare May 16, 2021 09:13
Copy link
Collaborator

@AlexandruGG AlexandruGG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this so quickly! 🚀

@drupol drupol merged commit ca0c9b9 into master May 16, 2021
@drupol drupol deleted the feat-add-squash-operation branch May 16, 2021 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlatMap + Eager Usage
2 participants