Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Laravel 5.4.10 changes (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Feb 8, 2017
1 parent 19e23db commit de4d58f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,19 @@ public function take($limit)
return $this->slice(0, $limit);
}

/**
* Pass the collection to the given callback and then return it.
*
* @param callable $callback
* @return $this
*/
public function tap(callable $callback)
{
$callback(new static($this->items));

return $this;
}

/**
* Transform each item in the collection using a callback.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,19 @@ public function testHigherOrderPartition()

$this->assertSame(['b' => ['free' => false]], $premium->toArray());
}

public function testTap()
{
$collection = new Collection([1, 2, 3]);

$fromTap = [];
$collection = $collection->tap(function ($collection) use (&$fromTap) {
$fromTap = $collection->slice(0, 1)->toArray();
});

$this->assertSame([1], $fromTap);
$this->assertSame([1, 2, 3], $collection->toArray());
}
}

class TestSupportCollectionHigherOrderItem
Expand Down

0 comments on commit de4d58f

Please sign in to comment.