Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,24 @@ public function forPage($page, $perPage)
return $this->slice(($page - 1) * $perPage, $perPage);
}

/**
* Returns an array with two elements. Items in the first element did pass
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please format like the other phpdoc, then looks good. 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid I don't see the formatting problem. Could you tell what's wrong with the current formatting?

Copy link
Copy Markdown
Collaborator

@GrahamCampbell GrahamCampbell Dec 2, 2016

Choose a reason for hiding this comment

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

Short descriptions must be "sort". Exactly one sentence and one line. The rest must be separated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks for clarifying

* the given $callback, items in the second element did not.
*
* @param callable $callback
* @return array
*/
public function partition(callable $callback)
{
$partitions = [new static(), new static()];

foreach ($this->items as $item) {
$partitions[! (int) $callback($item)][] = $item;
}

return $partitions;
}

/**
* Pass the collection to the given callback and return the result.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,27 @@ public function testSplitEmptyCollection()
})->toArray()
);
}

public function testPartition()
{
$collection = new Collection(range(1, 10));

list($firstPartition, $secondPartition) = $collection->partition(function ($i) {
return $i <= 5;
});

$this->assertEquals([1, 2, 3, 4, 5], $firstPartition->toArray());
$this->assertEquals([6, 7, 8, 9, 10], $secondPartition->toArray());
}

public function testPartitionEmptyCollection()
{
$collection = new Collection();

$this->assertCount(2, $collection->partition(function () {
return true;
}));
}
}

class TestAccessorEloquentTestStub
Expand Down