$collection = new Collection(['data' => array_merge(array_fill(0, 10, 1), array_fill(0, 10, 2))]); $filter = function ($item) { return $item === 1; }; $result = $collection->find($filter); expect($result)->toBeAnInstanceOf(Collection::class); expect($result->data())->toBe(array_fill(0, 10, 1)); }); }); describe("->map()", function () { it("applies a Closure to a copy of all data in the collection", function () { $collection = new Collection(['data' => [1, 2, 3, 4, 5]]); $filter = function ($item) { return ++$item; }; $result = $collection->map($filter); expect($result)->not->toBe($collection); expect($result->data())->toBe([2, 3, 4, 5, 6]); }); }); describe("->reduce()", function () { it("reduces a collection down to a single value", function () { $collection = new Collection(['data' => [1, 2, 3]]); $filter = function ($memo, $item) { return $memo + $item; }; expect($collection->reduce($filter, 0))->toBe(6); expect($collection->reduce($filter, 1))->toBe(7); }); }); describe("->slice()", function () {