Enumerable.php 34 KB

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