Debian Codegraph @

lib/3rdParty/composer/illuminate/collections/Enumerable.php

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support;
4
5 use CachingIterator;
6 use Countable;
7 use Illuminate\Contracts\Support\Arrayable;
8 use Illuminate\Contracts\Support\Jsonable;
9 use IteratorAggregate;
10 use JsonSerializable;
11 use Traversable;
12
13 /**
14 * @template TKey of array-key
15 *
16 * @template-covariant TValue
17 *
18 * @extends \Illuminate\Contracts\Support\Arrayable<TKey, TValue>
19 * @extends \IteratorAggregate<TKey, TValue>
20 */
21 interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable
22 {
23 /**
24 * Create a new collection instance if the value isn't one already.
25 *
26 * @template TMakeKey of array-key
27 * @template TMakeValue
28 *
29 * @param \Illuminate\Contracts\Support\Arrayable<TMakeKey, TMakeValue>|iterable<TMakeKey, TMakeValue>|null $items
30 * @return static<TMakeKey, TMakeValue>
31 */
32 public static function make($items = []);
33
34 /**
35 * Create a new instance by invoking the callback a given amount of times.
36 *
37 * @param int $number
38 * @param callable|null $callback
39 * @return static
40 */
41 public static function times($number, ?callable $callback = null);
42
43 /**
44 * Create a collection with the given range.
45 *
46 * @param int $from
47 * @param int $to
48 * @param int $step
49 * @return static
50 */
51 public static function range($from, $to, $step = 1);
52
53 /**
54 * Wrap the given value in a collection if applicable.
55 *
56 * @template TWrapValue
57 *
58 * @param iterable<array-key, TWrapValue>|TWrapValue $value
59 * @return static<array-key, TWrapValue>
60 */
61 public static function wrap($value);
62
63 /**
64 * Get the underlying items from the given collection if applicable.
65 *
66 * @template TUnwrapKey of array-key
67 * @template TUnwrapValue
68 *
69 * @param array<TUnwrapKey, TUnwrapValue>|static<TUnwrapKey, TUnwrapValue> $value
70 * @return array<TUnwrapKey, TUnwrapValue>
71 */
72 public static function unwrap($value);
73
74 /**
75 * Create a new instance with no items.
76 *
77 * @return static
78 */
79 public static function empty();
80
81 /**
82 * Get all items in the enumerable.
83 *
84 * @return array
85 */
86 public function all();
87
88 /**
89 * Alias for the "avg" method.
90 *
91 * @param (callable(TValue): float|int)|string|null $callback
92 * @return float|int|null
93 */
94 public function average($callback = null);
95
96 /**
97 * Get the median of a given key.
98 *
99 * @param string|array<array-key, string>|null $key
100 * @return float|int|null
101 */
102 public function median($key = null);
103
104 /**
105 * Get the mode of a given key.
106 *
107 * @param string|array<array-key, string>|null $key
108 * @return array<int, float|int>|null
109 */
110 public function mode($key = null);
111
112 /**
113 * Collapse the items into a single enumerable.
114 *
115 * @return static<int, mixed>
116 */
117 public function collapse();
118
119 /**
120 * Alias for the "contains" method.
121 *
122 * @param (callable(TValue, TKey): bool)|TValue|string $key
123 * @param mixed $operator
124 * @param mixed $value
125 * @return bool
126 */
127 public function some($key, $operator = null, $value = null);
128
129 /**
130 * Determine if an item exists, using strict comparison.
131 *
132 * @param (callable(TValue): bool)|TValue|array-key $key
133 * @param TValue|null $value
134 * @return bool
135 */
136 public function containsStrict($key, $value = null);
137
138 /**
139 * Get the average value of a given key.
140 *
141 * @param (callable(TValue): float|int)|string|null $callback
142 * @return float|int|null
143 */
144 public function avg($callback = null);
145
146 /**
147 * Determine if an item exists in the enumerable.
148 *
149 * @param (callable(TValue, TKey): bool)|TValue|string $key
150 * @param mixed $operator
151 * @param mixed $value
152 * @return bool
153 */
154 public function contains($key, $operator = null, $value = null);
155
156 /**
157 * Determine if an item is not contained in the collection.
158 *
159 * @param mixed $key
160 * @param mixed $operator
161 * @param mixed $value
162 * @return bool
163 */
164 public function doesntContain($key, $operator = null, $value = null);
165
166 /**
167 * Cross join with the given lists, returning all possible permutations.
168 *
169 * @template TCrossJoinKey
170 * @template TCrossJoinValue
171 *
172 * @param \Illuminate\Contracts\Support\Arrayable<TCrossJoinKey, TCrossJoinValue>|iterable<TCrossJoinKey, TCrossJoinValue> ...$lists
173 * @return static<int, array<int, TValue|TCrossJoinValue>>
174 */
175 public function crossJoin(...$lists);
176
177 /**
178 * Dump the collection and end the script.
179 *
180 * @param mixed ...$args
181 * @return never
182 */
183 public function dd(...$args);
184
185 /**
186 * Dump the collection.
187 *
188 * @param mixed ...$args
189 * @return $this
190 */
191 public function dump(...$args);
192
193 /**
194 * Get the items that are not present in the given items.
195 *
196 * @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
197 * @return static
198 */
199 public function diff($items);
200
201 /**
202 * Get the items that are not present in the given items, using the callback.
203 *
204 * @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
205 * @param callable(TValue, TValue): int $callback
206 * @return static
207 */
208 public function diffUsing($items, callable $callback);
209
210 /**
211 * Get the items whose keys and values are not present in the given items.
212 *
213 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
214 * @return static
215 */
216 public function diffAssoc($items);
217
218 /**
219 * Get the items whose keys and values are not present in the given items, using the callback.
220 *
221 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
222 * @param callable(TKey, TKey): int $callback
223 * @return static
224 */
225 public function diffAssocUsing($items, callable $callback);
226
227 /**
228 * Get the items whose keys are not present in the given items.
229 *
230 * @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
231 * @return static
232 */
233 public function diffKeys($items);
234
235 /**
236 * Get the items whose keys are not present in the given items, using the callback.
237 *
238 * @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
239 * @param callable(TKey, TKey): int $callback
240 * @return static
241 */
242 public function diffKeysUsing($items, callable $callback);
243
244 /**
245 * Retrieve duplicate items.
246 *
247 * @param (callable(TValue): bool)|string|null $callback
248 * @param bool $strict
249 * @return static
250 */
251 public function duplicates($callback = null, $strict = false);
252
253 /**
254 * Retrieve duplicate items using strict comparison.
255 *
256 * @param (callable(TValue): bool)|string|null $callback
257 * @return static
258 */
259 public function duplicatesStrict($callback = null);
260
261 /**
262 * Execute a callback over each item.
263 *
264 * @param callable(TValue, TKey): mixed $callback
265 * @return $this
266 */
267 public function each(callable $callback);
268
269 /**
270 * Execute a callback over each nested chunk of items.
271 *
272 * @param callable $callback
273 * @return static
274 */
275 public function eachSpread(callable $callback);
276
277 /**
278 * Determine if all items pass the given truth test.
279 *
280 * @param (callable(TValue, TKey): bool)|TValue|string $key
281 * @param mixed $operator
282 * @param mixed $value
283 * @return bool
284 */
285 public function every($key, $operator = null, $value = null);
286
287 /**
288 * Get all items except for those with the specified keys.
289 *
290 * @param \Illuminate\Support\Enumerable<array-key, TKey>|array<array-key, TKey> $keys
291 * @return static
292 */
293 public function except($keys);
294
295 /**
296 * Run a filter over each of the items.
297 *
298 * @param (callable(TValue): bool)|null $callback
299 * @return static
300 */
301 public function filter(?callable $callback = null);
302
303 /**
304 * Apply the callback if the given "value" is (or resolves to) truthy.
305 *
306 * @template TWhenReturnType as null
307 *
308 * @param bool $value
309 * @param (callable($this): TWhenReturnType)|null $callback
310 * @param (callable($this): TWhenReturnType)|null $default
311 * @return $this|TWhenReturnType
312 */
313 public function when($value, ?callable $callback = null, ?callable $default = null);
314
315 /**
316 * Apply the callback if the collection is empty.
317 *
318 * @template TWhenEmptyReturnType
319 *
320 * @param (callable($this): TWhenEmptyReturnType) $callback
321 * @param (callable($this): TWhenEmptyReturnType)|null $default
322 * @return $this|TWhenEmptyReturnType
323 */
324 public function whenEmpty(callable $callback, ?callable $default = null);
325
326 /**
327 * Apply the callback if the collection is not empty.
328 *
329 * @template TWhenNotEmptyReturnType
330 *
331 * @param callable($this): TWhenNotEmptyReturnType $callback
332 * @param (callable($this): TWhenNotEmptyReturnType)|null $default
333 * @return $this|TWhenNotEmptyReturnType
334 */
335 public function whenNotEmpty(callable $callback, ?callable $default = null);
336
337 /**
338 * Apply the callback if the given "value" is (or resolves to) falsy.
339 *
340 * @template TUnlessReturnType
341 *
342 * @param bool $value
343 * @param (callable($this): TUnlessReturnType) $callback
344 * @param (callable($this): TUnlessReturnType)|null $default
345 * @return $this|TUnlessReturnType
346 */
347 public function unless($value, callable $callback, ?callable $default = null);
348
349 /**
350 * Apply the callback unless the collection is empty.
351 *
352 * @template TUnlessEmptyReturnType
353 *
354 * @param callable($this): TUnlessEmptyReturnType $callback
355 * @param (callable($this): TUnlessEmptyReturnType)|null $default
356 * @return $this|TUnlessEmptyReturnType
357 */
358 public function unlessEmpty(callable $callback, ?callable $default = null);
359
360 /**
361 * Apply the callback unless the collection is not empty.
362 *
363 * @template TUnlessNotEmptyReturnType
364 *
365 * @param callable($this): TUnlessNotEmptyReturnType $callback
366 * @param (callable($this): TUnlessNotEmptyReturnType)|null $default
367 * @return $this|TUnlessNotEmptyReturnType
368 */
369 public function unlessNotEmpty(callable $callback, ?callable $default = null);
370
371 /**
372 * Filter items by the given key value pair.
373 *
374 * @param string $key
375 * @param mixed $operator
376 * @param mixed $value
377 * @return static
378 */
379 public function where($key, $operator = null, $value = null);
380
381 /**
382 * Filter items where the value for the given key is null.
383 *
384 * @param string|null $key
385 * @return static
386 */
387 public function whereNull($key = null);
388
389 /**
390 * Filter items where the value for the given key is not null.
391 *
392 * @param string|null $key
393 * @return static
394 */
395 public function whereNotNull($key = null);
396
397 /**
398 * Filter items by the given key value pair using strict comparison.
399 *
400 * @param string $key
401 * @param mixed $value
402 * @return static
403 */
404 public function whereStrict($key, $value);
405
406 /**
407 * Filter items by the given key value pair.
408 *
409 * @param string $key
410 * @param \Illuminate\Contracts\Support\Arrayable|iterable $values
411 * @param bool $strict
412 * @return static
413 */
414 public function whereIn($key, $values, $strict = false);
415
416 /**
417 * Filter items by the given key value pair using strict comparison.
418 *
419 * @param string $key
420 * @param \Illuminate\Contracts\Support\Arrayable|iterable $values
421 * @return static
422 */
423 public function whereInStrict($key, $values);
424
425 /**
426 * Filter items such that the value of the given key is between the given values.
427 *
428 * @param string $key
429 * @param \Illuminate\Contracts\Support\Arrayable|iterable $values
430 * @return static
431 */
432 public function whereBetween($key, $values);
433
434 /**
435 * Filter items such that the value of the given key is not between the given values.
436 *
437 * @param string $key
438 * @param \Illuminate\Contracts\Support\Arrayable|iterable $values
439 * @return static
440 */
441 public function whereNotBetween($key, $values);
442
443 /**
444 * Filter items by the given key value pair.
445 *
446 * @param string $key
447 * @param \Illuminate\Contracts\Support\Arrayable|iterable $values
448 * @param bool $strict
449 * @return static
450 */
451 public function whereNotIn($key, $values, $strict = false);
452
453 /**
454 * Filter items by the given key value pair using strict comparison.
455 *
456 * @param string $key
457 * @param \Illuminate\Contracts\Support\Arrayable|iterable $values
458 * @return static
459 */
460 public function whereNotInStrict($key, $values);
461
462 /**
463 * Filter the items, removing any items that don't match the given type(s).
464 *
465 * @template TWhereInstanceOf
466 *
467 * @param class-string<TWhereInstanceOf>|array<array-key, class-string<TWhereInstanceOf>> $type
468 * @return static<TKey, TWhereInstanceOf>
469 */
470 public function whereInstanceOf($type);
471
472 /**
473 * Get the first item from the enumerable passing the given truth test.
474 *
475 * @template TFirstDefault
476 *
477 * @param (callable(TValue,TKey): bool)|null $callback
478 * @param TFirstDefault|(\Closure(): TFirstDefault) $default
479 * @return TValue|TFirstDefault
480 */
481 public function first(?callable $callback = null, $default = null);
482
483 /**
484 * Get the first item by the given key value pair.
485 *
486 * @param string $key
487 * @param mixed $operator
488 * @param mixed $value
489 * @return TValue|null
490 */
491 public function firstWhere($key, $operator = null, $value = null);
492
493 /**
494 * Get a flattened array of the items in the collection.
495 *
496 * @param int $depth
497 * @return static
498 */
499 public function flatten($depth = INF);
500
501 /**
502 * Flip the values with their keys.
503 *
504 * @return static<TValue, TKey>
505 */
506 public function flip();
507
508 /**
509 * Get an item from the collection by key.
510 *
511 * @template TGetDefault
512 *
513 * @param TKey $key
514 * @param TGetDefault|(\Closure(): TGetDefault) $default
515 * @return TValue|TGetDefault
516 */
517 public function get($key, $default = null);
518
519 /**
520 * Group an associative array by a field or using a callback.
521 *
522 * @template TGroupKey of array-key
523 *
524 * @param (callable(TValue, TKey): TGroupKey)|array|string $groupBy
525 * @param bool $preserveKeys
526 * @return static<($groupBy is string ? array-key : ($groupBy is array ? array-key : TGroupKey)), static<($preserveKeys is true ? TKey : int), ($groupBy is array ? mixed : TValue)>>
527 */
528 public function groupBy($groupBy, $preserveKeys = false);
529
530 /**
531 * Key an associative array by a field or using a callback.
532 *
533 * @template TNewKey of array-key
534 *
535 * @param (callable(TValue, TKey): TNewKey)|array|string $keyBy
536 * @return static<($keyBy is string ? array-key : ($keyBy is array ? array-key : TNewKey)), TValue>
537 */
538 public function keyBy($keyBy);
539
540 /**
541 * Determine if an item exists in the collection by key.
542 *
543 * @param TKey|array<array-key, TKey> $key
544 * @return bool
545 */
546 public function has($key);
547
548 /**
549 * Determine if any of the keys exist in the collection.
550 *
551 * @param mixed $key
552 * @return bool
553 */
554 public function hasAny($key);
555
556 /**
557 * Concatenate values of a given key as a string.
558 *
559 * @param (callable(TValue, TKey): mixed)|string $value
560 * @param string|null $glue
561 * @return string
562 */
563 public function implode($value, $glue = null);
564
565 /**
566 * Intersect the collection with the given items.
567 *
568 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
569 * @return static
570 */
571 public function intersect($items);
572
573 /**
574 * Intersect the collection with the given items, using the callback.
575 *
576 * @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
577 * @param callable(TValue, TValue): int $callback
578 * @return static
579 */
580 public function intersectUsing($items, callable $callback);
581
582 /**
583 * Intersect the collection with the given items with additional index check.
584 *
585 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
586 * @return static
587 */
588 public function intersectAssoc($items);
589
590 /**
591 * Intersect the collection with the given items with additional index check, using the callback.
592 *
593 * @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
594 * @param callable(TValue, TValue): int $callback
595 * @return static
596 */
597 public function intersectAssocUsing($items, callable $callback);
598
599 /**
600 * Intersect the collection with the given items by key.
601 *
602 * @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
603 * @return static
604 */
605 public function intersectByKeys($items);
606
607 /**
608 * Determine if the collection is empty or not.
609 *
610 * @return bool
611 */
612 public function isEmpty();
613
614 /**
615 * Determine if the collection is not empty.
616 *
617 * @return bool
618 */
619 public function isNotEmpty();
620
621 /**
622 * Determine if the collection contains a single item.
623 *
624 * @return bool
625 */
626 public function containsOneItem();
627
628 /**
629 * Determine if the collection contains multiple items.
630 *
631 * @return bool
632 */
633 public function containsManyItems();
634
635 /**
636 * Join all items from the collection using a string. The final items can use a separate glue string.
637 *
638 * @param string $glue
639 * @param string $finalGlue
640 * @return string
641 */
642 public function join($glue, $finalGlue = '');
643
644 /**
645 * Get the keys of the collection items.
646 *
647 * @return static<int, TKey>
648 */
649 public function keys();
650
651 /**
652 * Get the last item from the collection.
653 *
654 * @template TLastDefault
655 *
656 * @param (callable(TValue, TKey): bool)|null $callback
657 * @param TLastDefault|(\Closure(): TLastDefault) $default
658 * @return TValue|TLastDefault
659 */
660 public function last(?callable $callback = null, $default = null);
661
662 /**
663 * Run a map over each of the items.
664 *
665 * @template TMapValue
666 *
667 * @param callable(TValue, TKey): TMapValue $callback
668 * @return static<TKey, TMapValue>
669 */
670 public function map(callable $callback);
671
672 /**
673 * Run a map over each nested chunk of items.
674 *
675 * @param callable $callback
676 * @return static
677 */
678 public function mapSpread(callable $callback);
679
680 /**
681 * Run a dictionary map over the items.
682 *
683 * The callback should return an associative array with a single key/value pair.
684 *
685 * @template TMapToDictionaryKey of array-key
686 * @template TMapToDictionaryValue
687 *
688 * @param callable(TValue, TKey): array<TMapToDictionaryKey, TMapToDictionaryValue> $callback
689 * @return static<TMapToDictionaryKey, array<int, TMapToDictionaryValue>>
690 */
691 public function mapToDictionary(callable $callback);
692
693 /**
694 * Run a grouping map over the items.
695 *
696 * The callback should return an associative array with a single key/value pair.
697 *
698 * @template TMapToGroupsKey of array-key
699 * @template TMapToGroupsValue
700 *
701 * @param callable(TValue, TKey): array<TMapToGroupsKey, TMapToGroupsValue> $callback
702 * @return static<TMapToGroupsKey, static<int, TMapToGroupsValue>>
703 */
704 public function mapToGroups(callable $callback);
705
706 /**
707 * Run an associative map over each of the items.
708 *
709 * The callback should return an associative array with a single key/value pair.
710 *
711 * @template TMapWithKeysKey of array-key
712 * @template TMapWithKeysValue
713 *
714 * @param callable(TValue, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback
715 * @return static<TMapWithKeysKey, TMapWithKeysValue>
716 */
717 public function mapWithKeys(callable $callback);
718
719 /**
720 * Map a collection and flatten the result by a single level.
721 *
722 * @template TFlatMapKey of array-key
723 * @template TFlatMapValue
724 *
725 * @param callable(TValue, TKey): (\Illuminate\Support\Collection<TFlatMapKey, TFlatMapValue>|array<TFlatMapKey, TFlatMapValue>) $callback
726 * @return static<TFlatMapKey, TFlatMapValue>
727 */
728 public function flatMap(callable $callback);
729
730 /**
731 * Map the values into a new class.
732 *
733 * @template TMapIntoValue
734 *
735 * @param class-string<TMapIntoValue> $class
736 * @return static<TKey, TMapIntoValue>
737 */
738 public function mapInto($class);
739
740 /**
741 * Merge the collection with the given items.
742 *
743 * @template TMergeValue
744 *
745 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TMergeValue>|iterable<TKey, TMergeValue> $items
746 * @return static<TKey, TValue|TMergeValue>
747 */
748 public function merge($items);
749
750 /**
751 * Recursively merge the collection with the given items.
752 *
753 * @template TMergeRecursiveValue
754 *
755 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TMergeRecursiveValue>|iterable<TKey, TMergeRecursiveValue> $items
756 * @return static<TKey, TValue|TMergeRecursiveValue>
757 */
758 public function mergeRecursive($items);
759
760 /**
761 * Create a collection by using this collection for keys and another for its values.
762 *
763 * @template TCombineValue
764 *
765 * @param \Illuminate\Contracts\Support\Arrayable<array-key, TCombineValue>|iterable<array-key, TCombineValue> $values
766 * @return static<TValue, TCombineValue>
767 */
768 public function combine($values);
769
770 /**
771 * Union the collection with the given items.
772 *
773 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
774 * @return static
775 */
776 public function union($items);
777
778 /**
779 * Get the min value of a given key.
780 *
781 * @param (callable(TValue):mixed)|string|null $callback
782 * @return mixed
783 */
784 public function min($callback = null);
785
786 /**
787 * Get the max value of a given key.
788 *
789 * @param (callable(TValue):mixed)|string|null $callback
790 * @return mixed
791 */
792 public function max($callback = null);
793
794 /**
795 * Create a new collection consisting of every n-th element.
796 *
797 * @param int $step
798 * @param int $offset
799 * @return static
800 */
801 public function nth($step, $offset = 0);
802
803 /**
804 * Get the items with the specified keys.
805 *
806 * @param \Illuminate\Support\Enumerable<array-key, TKey>|array<array-key, TKey>|string $keys
807 * @return static
808 */
809 public function only($keys);
810
811 /**
812 * "Paginate" the collection by slicing it into a smaller collection.
813 *
814 * @param int $page
815 * @param int $perPage
816 * @return static
817 */
818 public function forPage($page, $perPage);
819
820 /**
821 * Partition the collection into two arrays using the given callback or key.
822 *
823 * @param (callable(TValue, TKey): bool)|TValue|string $key
824 * @param mixed $operator
825 * @param mixed $value
826 * @return static<int<0, 1>, static<TKey, TValue>>
827 */
828 public function partition($key, $operator = null, $value = null);
829
830 /**
831 * Push all of the given items onto the collection.
832 *
833 * @template TConcatKey of array-key
834 * @template TConcatValue
835 *
836 * @param iterable<TConcatKey, TConcatValue> $source
837 * @return static<TKey|TConcatKey, TValue|TConcatValue>
838 */
839 public function concat($source);
840
841 /**
842 * Get one or a specified number of items randomly from the collection.
843 *
844 * @param int|null $number
845 * @return static<int, TValue>|TValue
846 *
847 * @throws \InvalidArgumentException
848 */
849 public function random($number = null);
850
851 /**
852 * Reduce the collection to a single value.
853 *
854 * @template TReduceInitial
855 * @template TReduceReturnType
856 *
857 * @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback
858 * @param TReduceInitial $initial
859 * @return TReduceInitial|TReduceReturnType
860 */
861 public function reduce(callable $callback, $initial = null);
862
863 /**
864 * Reduce the collection to multiple aggregate values.
865 *
866 * @param callable $callback
867 * @param mixed ...$initial
868 * @return array
869 *
870 * @throws \UnexpectedValueException
871 */
872 public function reduceSpread(callable $callback, ...$initial);
873
874 /**
875 * Replace the collection items with the given items.
876 *
877 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
878 * @return static
879 */
880 public function replace($items);
881
882 /**
883 * Recursively replace the collection items with the given items.
884 *
885 * @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
886 * @return static
887 */
888 public function replaceRecursive($items);
889
890 /**
891 * Reverse items order.
892 *
893 * @return static
894 */
895 public function reverse();
896
897 /**
898 * Search the collection for a given value and return the corresponding key if successful.
899 *
900 * @param TValue|callable(TValue,TKey): bool $value
901 * @param bool $strict
902 * @return TKey|bool
903 */
904 public function search($value, $strict = false);
905
906 /**
907 * Get the item before the given item.
908 *
909 * @param TValue|(callable(TValue,TKey): bool) $value
910 * @param bool $strict
911 * @return TValue|null
912 */
913 public function before($value, $strict = false);
914
915 /**
916 * Get the item after the given item.
917 *
918 * @param TValue|(callable(TValue,TKey): bool) $value
919 * @param bool $strict
920 * @return TValue|null
921 */
922 public function after($value, $strict = false);
923
924 /**
925 * Shuffle the items in the collection.
926 *
927 * @return static
928 */
929 public function shuffle();
930
931 /**
932 * Create chunks representing a "sliding window" view of the items in the collection.
933 *
934 * @param int $size
935 * @param int $step
936 * @return static<int, static>
937 */
938 public function sliding($size = 2, $step = 1);
939
940 /**
941 * Skip the first {$count} items.
942 *
943 * @param int $count
944 * @return static
945 */
946 public function skip($count);
947
948 /**
949 * Skip items in the collection until the given condition is met.
950 *
951 * @param TValue|callable(TValue,TKey): bool $value
952 * @return static
953 */
954 public function skipUntil($value);
955
956 /**
957 * Skip items in the collection while the given condition is met.
958 *
959 * @param TValue|callable(TValue,TKey): bool $value
960 * @return static
961 */
962 public function skipWhile($value);
963
964 /**
965 * Get a slice of items from the enumerable.
966 *
967 * @param int $offset
968 * @param int|null $length
969 * @return static
970 */
971 public function slice($offset, $length = null);
972
973 /**
974 * Split a collection into a certain number of groups.
975 *
976 * @param int $numberOfGroups
977 * @return static<int, static>
978 */
979 public function split($numberOfGroups);
980
981 /**
982 * Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
983 *
984 * @param (callable(TValue, TKey): bool)|string $key
985 * @param mixed $operator
986 * @param mixed $value
987 * @return TValue
988 *
989 * @throws \Illuminate\Support\ItemNotFoundException
990 * @throws \Illuminate\Support\MultipleItemsFoundException
991 */
992 public function sole($key = null, $operator = null, $value = null);
993
994 /**
995 * Get the first item in the collection but throw an exception if no matching items exist.
996 *
997 * @param (callable(TValue, TKey): bool)|string|null $key
998 * @param mixed $operator
999 * @param mixed $value
1000 * @return TValue
1001 *
1002 * @throws \Illuminate\Support\ItemNotFoundException
1003 */
1004 public function firstOrFail($key = null, $operator = null, $value = null);
1005
1006 /**
1007 * Chunk the collection into chunks of the given size.
1008 *
1009 * @param int $size
1010 * @return static<int, static>
1011 */
1012 public function chunk($size);
1013
1014 /**
1015 * Chunk the collection into chunks with a callback.
1016 *
1017 * @param callable(TValue, TKey, static<int, TValue>): bool $callback
1018 * @return static<int, static<int, TValue>>
1019 */
1020 public function chunkWhile(callable $callback);
1021
1022 /**
1023 * Split a collection into a certain number of groups, and fill the first groups completely.
1024 *
1025 * @param int $numberOfGroups
1026 * @return static<int, static>
1027 */
1028 public function splitIn($numberOfGroups);
1029
1030 /**
1031 * Sort through each item with a callback.
1032 *
1033 * @param (callable(TValue, TValue): int)|null|int $callback
1034 * @return static
1035 */
1036 public function sort($callback = null);
1037
1038 /**
1039 * Sort items in descending order.
1040 *
1041 * @param int $options
1042 * @return static
1043 */
1044 public function sortDesc($options = SORT_REGULAR);
1045
1046 /**
1047 * Sort the collection using the given callback.
1048 *
1049 * @param array<array-key, (callable(TValue, TValue): mixed)|(callable(TValue, TKey): mixed)|string|array{string, string}>|(callable(TValue, TKey): mixed)|string $callback
1050 * @param int $options
1051 * @param bool $descending
1052 * @return static
1053 */
1054 public function sortBy($callback, $options = SORT_REGULAR, $descending = false);
1055
1056 /**
1057 * Sort the collection in descending order using the given callback.
1058 *
1059 * @param array<array-key, (callable(TValue, TValue): mixed)|(callable(TValue, TKey): mixed)|string|array{string, string}>|(callable(TValue, TKey): mixed)|string $callback
1060 * @param int $options
1061 * @return static
1062 */
1063 public function sortByDesc($callback, $options = SORT_REGULAR);
1064
1065 /**
1066 * Sort the collection keys.
1067 *
1068 * @param int $options
1069 * @param bool $descending
1070 * @return static
1071 */
1072 public function sortKeys($options = SORT_REGULAR, $descending = false);
1073
1074 /**
1075 * Sort the collection keys in descending order.
1076 *
1077 * @param int $options
1078 * @return static
1079 */
1080 public function sortKeysDesc($options = SORT_REGULAR);
1081
1082 /**
1083 * Sort the collection keys using a callback.
1084 *
1085 * @param callable(TKey, TKey): int $callback
1086 * @return static
1087 */
1088 public function sortKeysUsing(callable $callback);
1089
1090 /**
1091 * Get the sum of the given values.
1092 *
1093 * @param (callable(TValue): mixed)|string|null $callback
1094 * @return mixed
1095 */
1096 public function sum($callback = null);
1097
1098 /**
1099 * Take the first or last {$limit} items.
1100 *
1101 * @param int $limit
1102 * @return static
1103 */
1104 public function take($limit);
1105
1106 /**
1107 * Take items in the collection until the given condition is met.
1108 *
1109 * @param TValue|callable(TValue,TKey): bool $value
1110 * @return static
1111 */
1112 public function takeUntil($value);
1113
1114 /**
1115 * Take items in the collection while the given condition is met.
1116 *
1117 * @param TValue|callable(TValue,TKey): bool $value
1118 * @return static
1119 */
1120 public function takeWhile($value);
1121
1122 /**
1123 * Pass the collection to the given callback and then return it.
1124 *
1125 * @param callable(TValue): mixed $callback
1126 * @return $this
1127 */
1128 public function tap(callable $callback);
1129
1130 /**
1131 * Pass the enumerable to the given callback and return the result.
1132 *
1133 * @template TPipeReturnType
1134 *
1135 * @param callable($this): TPipeReturnType $callback
1136 * @return TPipeReturnType
1137 */
1138 public function pipe(callable $callback);
1139
1140 /**
1141 * Pass the collection into a new class.
1142 *
1143 * @template TPipeIntoValue
1144 *
1145 * @param class-string<TPipeIntoValue> $class
1146 * @return TPipeIntoValue
1147 */
1148 public function pipeInto($class);
1149
1150 /**
1151 * Pass the collection through a series of callable pipes and return the result.
1152 *
1153 * @param array<callable> $pipes
1154 * @return mixed
1155 */
1156 public function pipeThrough($pipes);
1157
1158 /**
1159 * Get the values of a given key.
1160 *
1161 * @param string|array<array-key, string> $value
1162 * @param string|null $key
1163 * @return static<array-key, mixed>
1164 */
1165 public function pluck($value, $key = null);
1166
1167 /**
1168 * Create a collection of all elements that do not pass a given truth test.
1169 *
1170 * @param (callable(TValue, TKey): bool)|bool|TValue $callback
1171 * @return static
1172 */
1173 public function reject($callback = true);
1174
1175 /**
1176 * Convert a flatten "dot" notation array into an expanded array.
1177 *
1178 * @return static
1179 */
1180 public function undot();
1181
1182 /**
1183 * Return only unique items from the collection array.
1184 *
1185 * @param (callable(TValue, TKey): mixed)|string|null $key
1186 * @param bool $strict
1187 * @return static
1188 */
1189 public function unique($key = null, $strict = false);
1190
1191 /**
1192 * Return only unique items from the collection array using strict comparison.
1193 *
1194 * @param (callable(TValue, TKey): mixed)|string|null $key
1195 * @return static
1196 */
1197 public function uniqueStrict($key = null);
1198
1199 /**
1200 * Reset the keys on the underlying array.
1201 *
1202 * @return static<int, TValue>
1203 */
1204 public function values();
1205
1206 /**
1207 * Pad collection to the specified length with a value.
1208 *
1209 * @template TPadValue
1210 *
1211 * @param int $size
1212 * @param TPadValue $value
1213 * @return static<int, TValue|TPadValue>
1214 */
1215 public function pad($size, $value);
1216
1217 /**
1218 * Get the values iterator.
1219 *
1220 * @return \Traversable<TKey, TValue>
1221 */
1222 public function getIterator(): Traversable;
1223
1224 /**
1225 * Count the number of items in the collection.
1226 *
1227 * @return int
1228 */
1229 public function count(): int;
1230
1231 /**
1232 * Count the number of items in the collection by a field or using a callback.
1233 *
1234 * @param (callable(TValue, TKey): array-key)|string|null $countBy
1235 * @return static<array-key, int>
1236 */
1237 public function countBy($countBy = null);
1238
1239 /**
1240 * Zip the collection together with one or more arrays.
1241 *
1242 * e.g. new Collection([1, 2, 3])->zip([4, 5, 6]);
1243 * => [[1, 4], [2, 5], [3, 6]]
1244 *
1245 * @template TZipValue
1246 *
1247 * @param \Illuminate\Contracts\Support\Arrayable<array-key, TZipValue>|iterable<array-key, TZipValue> ...$items
1248 * @return static<int, static<int, TValue|TZipValue>>
1249 */
1250 public function zip($items);
1251
1252 /**
1253 * Collect the values into a collection.
1254 *
1255 * @return \Illuminate\Support\Collection<TKey, TValue>
1256 */
1257 public function collect();
1258
1259 /**
1260 * Get the collection of items as a plain array.
1261 *
1262 * @return array<TKey, mixed>
1263 */
1264 public function toArray();
1265
1266 /**
1267 * Convert the object into something JSON serializable.
1268 *
1269 * @return mixed
1270 */
1271 public function jsonSerialize(): mixed;
1272
1273 /**
1274 * Get the collection of items as JSON.
1275 *
1276 * @param int $options
1277 * @return string
1278 */
1279 public function toJson($options = 0);
1280
1281 /**
1282 * Get the collection of items as pretty print formatted JSON.
1283 *
1284 *
1285 * @param int $options
1286 * @return string
1287 */
1288 public function toPrettyJson(int $options = 0);
1289
1290 /**
1291 * Get a CachingIterator instance.
1292 *
1293 * @param int $flags
1294 * @return \CachingIterator
1295 */
1296 public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING);
1297
1298 /**
1299 * Convert the collection to its string representation.
1300 *
1301 * @return string
1302 */
1303 public function __toString();
1304
1305 /**
1306 * Indicate that the model's string representation should be escaped when __toString is invoked.
1307 *
1308 * @param bool $escape
1309 * @return $this
1310 */
1311 public function escapeWhenCastingToString($escape = true);
1312
1313 /**
1314 * Add a method to the list of proxied methods.
1315 *
1316 * @param string $method
1317 * @return void
1318 */
1319 public static function proxy($method);
1320
1321 /**
1322 * Dynamically access collection proxies.
1323 *
1324 * @param string $key
1325 * @return mixed
1326 *
1327 * @throws \Exception
1328 */
1329 public function __get($key);
1330 }