Skip to content

Commit

Permalink
Documenting zip() and zipWith()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 16, 2015
1 parent 2911a03 commit 79dfff5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/Collection/CollectionInterface.php
Expand Up @@ -819,7 +819,7 @@ public function unfold(callable $transformer = null);
* ### Example:
*
* ```
* $items [1, 2, 3];
* $items = [1, 2, 3];
* $decorated = (new Collection($items))->through(function ($collection) {
* return new MyCustomCollection($collection);
* });
Expand All @@ -831,6 +831,44 @@ public function unfold(callable $transformer = null);
*/
public function through(callable $handler);

/**
* Combines the elements of this collection with each of the elements of the
* passed iterables, using their positional index as a reference.
*
* ### Example:
*
* ```
* $collection = new Collection([1, 2]);
* $collection->zip([3, 4], [5, 6])->toList(); // returns [[1, 3, 5], [2, 4, 6]]
* ```
*
* @param array|\Traversable ...$items The collections to zip.
* @return \Cake\Collection\CollectionInterface
*/
public function zip($items);

/**
* Combines the elements of this collection with each of the elements of the
* passed iterables, using their positional index as a reference.
*
* The resulting element will be the return value of the $callable function.
*
* ### Example:
*
* ```
* $collection = new Collection([1, 2]);
* $zipped = $collection->zip([3, 4], [5, 6], function () {
* return array_sum(func_get_args());
* });
* $zipped->toList(); // returns [9, 12]; [(1 + 3 + 5), (2 + 4 + 6)]
* ```
*
* @param array|\Traversable ...$items The collections to zip.
* @param callable $callable The function to use for zipping the elements together.
* @return \Cake\Collection\CollectionInterface
*/
public function zipWith($items, $callable);

/**
* Returns whether or not there are elements in this collection
*
Expand All @@ -840,6 +878,7 @@ public function through(callable $handler);
* $items [1, 2, 3];
* (new Collection($items))->isEmpty(); // false
* ```
*
* ```
* (new Collection([]))->isEmpty(); // true
* ```
Expand Down

0 comments on commit 79dfff5

Please sign in to comment.