-
-
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 Documentation III #88
Conversation
@drupol There are methods in the Collection implementation that are not included in the Collection Interface, and are not mentioned as methods in the documentation either. A few examples I noticed: Before I added them I wanted to check with you:
Lastly, a related question: when the library is used in another project, should the interface or the implementation be used in function and method arguments and return types? My instinct says the interface but then the two should be kept in sync otherwise it can result in issues. |
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 minor changes.
Indeed, those are missing and we should fix that.
Definitely, without hesitation.
I see, this is linked to your previous questions. I always try to rely on the |
Thanks for the quick reply on this. I think I was blind when I said things are not in the interface 😄 . They are there actually, just some things missing from the documentation, which I will add. |
@@ -57,5 +57,5 @@ | |||
* "(4, b)" | |||
* "(3, c)" | |||
* "(4, d)" | |||
* "(5, e)" | |||
* "(5, e)". |
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.
ahaha we can disable that rule if it's really a problem :)
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.
Nah it's fine I think it's useful for php docs in general 😄
pipe | ||
~~~~ | ||
|
||
Pipe together multiple operations and apply them in succession to the collection items. | ||
To maintain a lazy nature, each operation needs to return a ``Generator``. | ||
Custom operations and operations provided in the API can be combined together. | ||
|
||
Interface: `Pipeable`_ | ||
|
||
Signature: ``Collection::pipe(callable ...$callables);`` | ||
|
||
.. code-block:: php | ||
|
||
$square = static function ($collection): Generator { | ||
foreach ($collection as $item) { | ||
yield $item ** 2; | ||
} | ||
}; | ||
|
||
$toString = static function ($collection): Generator { | ||
foreach ($collection as $item) { | ||
yield (string) $item; | ||
} | ||
}; | ||
|
||
$times = new class() extends AbstractOperation { | ||
public function __invoke(): Closure | ||
{ | ||
return static function ($collection): Generator { | ||
foreach ($collection as $item) { | ||
yield "{$item}x"; | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
Collection::fromIterable(range(1, 5)) | ||
->pipe($square, Reverse::of(), $toString, $times()) | ||
->all(); // ['25x', '16x', '9x', '4x', '1x'] | ||
|
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 hope this is a good definition and showcase of pipe
. Let me know if you think anything else should be included in the description.
Another thing I noticed: it's return type is self
vs CollectionInterface
like most other methods: https://github.com/loophp/collection/blob/master/src/Collection.php#L610. Is that just an error or was there a reason for 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.
This is something that I should sort one day. Returning self
or the interface
. I haven't found a proper way to do it yet.
Regarding the explanation, it's perfect :)
Thanks for your time and dedication, I'm glad and grateful to receive such pull requests! |
This PR updates more items in the documentation
Follows #86.