Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions stubs/common/Collection.stub
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
* @return static<($keyBy is string ? array-key : ($keyBy is array ? array-key : TNewKey)), TValue>
*/
public function keyBy($keyBy);

/**
* Chunk the collection into chunks with a callback.
*
* @param callable(TValue, TKey, static<TKey, TValue>): bool $callback
* @return static<int, static<TKey, TValue>>
*/
public function chunkWhile(callable $callback);
}

/**
Expand All @@ -100,4 +108,12 @@ class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable
* @return static<array-key, TCombineValue>
*/
public function combine($values);

/**
* Chunk the collection into chunks with a callback.
*
* @param callable(TValue, TKey, static<TKey, TValue>): bool $callback
* @return static<int, static<TKey, TValue>>
*/
public function chunkWhile(callable $callback);
}
8 changes: 8 additions & 0 deletions stubs/common/Enumerable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ interface Enumerable extends \Countable, \IteratorAggregate, \JsonSerializable,
* @return static<array-key, TCombineValue>
*/
public function combine($values);

/**
* Chunk the collection into chunks with a callback.
*
* @param callable(TValue, TKey, static<TKey, TValue>): bool $callback
* @return static<int, static<TKey, TValue>>
*/
public function chunkWhile(callable $callback);
}
2 changes: 1 addition & 1 deletion tests/Type/data/collection-generic-static-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function test(
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Database\Eloquent\Collection<int, App\User>>', $collection->chunkWhile(fn (User $u) => $u->id > 5));
assertType('App\TransactionCollection<int, App\TransactionCollection<int, App\Transaction>>', $customEloquentCollection->chunkWhile(fn (Transaction $t) => $t->id > 5));
assertType('App\UserCollection', $secondCustomEloquentCollection->chunkWhile(fn (User $t) => $t->id > 5));
assertType('Illuminate\Support\Collection<int, Illuminate\Support\Collection<int, int>>', $items->chunkWhile(fn ($v) => $v > 5));
assertType('Illuminate\Support\Collection<int, Illuminate\Support\Collection<string, int>>', $items->chunkWhile(fn ($v) => $v > 5));

assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', $collection->values());
assertType('App\TransactionCollection<int, App\Transaction>', $customEloquentCollection->values());
Expand Down