-
-
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
Plus operation RFC #313
Comments
Hi there! Super cool idea ! Are you willing to submit a PR? Thanks |
Hi Pol, thanks for quick response! Great to hear that! Well, currently I have zero experience with functional programming and I doubt if this task is feasible for me. At least for now, this library looks like a black box with some magic inside. Not because something is wrong with it, - conversely it is me who is FP freshmen. Thus, there will be no pull request from my side soon. |
OK I understand, no problem! I'll look into it when I have a bit of time. Sponsoring is greatly appreciated though. |
It would be nice Though, I'm not sure where to start from. I assume at first I should check documentation page https://loophp-collection.readthedocs.io/en/latest/pages/tests.html , but what should I do then? Maybe you could point out some similar test(s) examples I can inspire implementation from. And "Static analysis tests" - something really new to me. Thank you |
You could simply checkout the branch containing the new operation and create a simple file in the root of the project <?php
declare(strict_types=1);
namespace Test;
use loophp\collection\Collection;
require_once __DIR__ . '/vendor/autoload.php';
$collection = Collection::fromIterable([1, 2, 3])
->plus([4, 5, 6])
->plus(['a' => 'a']);
foreach ($collection as $i => $r) {
var_dump($r);
} So that you can play with the new operation and see if it corresponds to what you were expecting. |
I've checked it. Works like a charm! It does exactly what is expected. If you wish to add some unit tests, as a starting point you may use the following test case from my branch feat/add-plus-operation...rela589n:loophp-collection:feat/add-plus-operation Thank you! |
Thanks! What would really help me is to create the documentation and the code example. |
Since this issue has not had any activity within the last 5 days, I have marked it as stale. |
@rela589n Are you willing to contribute to the documentation of the associated PR ? |
PHP plus operator
I'm wondering if there's same feature as php plus operator:
As of me, personally I often use plus operation on arrays and it would make sense to implement it within a collection.
How it'd look like with collection
Comparison with
prepend
With current implementation seemingly the same behavior may be achieved using prepend:
However it is not explicit solution, since the collection maintains all the keys until
all()
is called.Therefore, when using
prepend
, we must convert collection into array before we can safely use the result, lest same instance iteration would yieldid
andid2
keys twice andid3
key before the rest.Please, let me know what you think about this
plus()
proposal.The text was updated successfully, but these errors were encountered: