seboettg /
Collection
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | /* |
||
| 4 | * Copyright (C) 2018 Sebastian Böttger <[email protected]> |
||
| 5 | * You may use, distribute and modify this code under the |
||
| 6 | * terms of the MIT license. |
||
| 7 | * |
||
| 8 | * You should have received a copy of the MIT license with |
||
| 9 | * this file. If not, please visit: https://opensource.org/licenses/mit-license.php |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Seboettg\Collection\Lists; |
||
| 13 | |||
| 14 | use Countable; |
||
| 15 | use Iterator; |
||
| 16 | use Seboettg\Collection\Assert\Exception\NotConvertibleToStringException; |
||
| 17 | use Seboettg\Collection\CollectionInterface; |
||
| 18 | use Seboettg\Collection\Lists\ListFeatures\ListAccessInterface; |
||
| 19 | use Seboettg\Collection\Lists\ListFeatures\ListOperationsInterface; |
||
| 20 | use Seboettg\Collection\Lists\MapFeatures\MapFeaturesInterface; |
||
| 21 | use Seboettg\Collection\Map\MapInterface; |
||
| 22 | use Traversable; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Interface ArrayListInterface |
||
| 26 | * @package Seboettg\Collection\ArrayList |
||
| 27 | */ |
||
| 28 | interface ListInterface extends CollectionInterface, ListAccessInterface, Traversable, Countable, ToArrayInterface, |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 29 | Iterator, ListOperationsInterface, MapFeaturesInterface |
||
|
0 ignored issues
–
show
|
|||
| 30 | { |
||
| 31 | /** |
||
| 32 | * alias of replace function |
||
| 33 | * @param array $array |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | public function setArray(array $array): void; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param array $array |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | public function replace(array $array): void; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Appends the passed element to the end of this list. |
||
| 46 | * |
||
| 47 | * @param $element |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | public function add($element): void; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Appends all passed elements to the end of this list. |
||
| 54 | * |
||
| 55 | * @param iterable $elements |
||
| 56 | * @return void |
||
| 57 | */ |
||
| 58 | public function addAll(iterable $elements): void; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Removes the element at the specified position in this list. |
||
| 62 | * |
||
| 63 | * @param int $key |
||
| 64 | * @return void |
||
| 65 | */ |
||
| 66 | public function remove(int $key): void; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Returns true if the passed element already exists in this list, otherwise false. |
||
| 70 | * |
||
| 71 | * @param mixed $element |
||
| 72 | * @return bool |
||
| 73 | */ |
||
| 74 | public function contains($element): bool; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * flush array list |
||
| 78 | * |
||
| 79 | */ |
||
| 80 | public function clear(): void; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Returns a new this list containing all values but randomizes the order of the elements in. |
||
| 84 | * |
||
| 85 | * @return ListInterface |
||
| 86 | */ |
||
| 87 | public function shuffle(): ListInterface; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Returns a list containing only elements matching the given predicate. |
||
| 91 | * |
||
| 92 | * @param ?callable|null $predicate |
||
| 93 | * @param bool $preserveKeys default false |
||
| 94 | * @return ListInterface |
||
| 95 | */ |
||
| 96 | public function filter(?callable $predicate = null, bool $preserveKeys = false): ListInterface; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * returns a new ArrayList containing all the elements of this ArrayList after applying the callback function to each one. |
||
| 100 | * @param callable $mapFunction |
||
| 101 | * @return ListInterface |
||
| 102 | */ |
||
| 103 | public function map(callable $mapFunction): ListInterface; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Same as <code>map</code> but removes null values from the new list |
||
| 107 | * @param callable $mapFunction |
||
| 108 | * @return ListInterface |
||
| 109 | */ |
||
| 110 | public function mapNotNull(callable $mapFunction): ListInterface; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Returns a new ArrayList of all elements from all collections in the given collection. |
||
| 114 | * @return ListInterface |
||
| 115 | */ |
||
| 116 | public function flatten(): ListInterface; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Expects a callable function which collects the elements of this list and returns any object. The callable |
||
| 120 | * function gets passed the entire array of the list |
||
| 121 | * |
||
| 122 | * @param callable $collectionFunction f(array) -> mixed |
||
| 123 | * @return mixed |
||
| 124 | */ |
||
| 125 | public function collect(callable $collectionFunction); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Tries to convert each element of the list to a string and concatenates them with given delimiter. |
||
| 129 | * Throws a <code>NotConvertibleToStringException</code> if any of the objects in the list is not a |
||
| 130 | * string or is not convertible to string. |
||
| 131 | * |
||
| 132 | * @param string $delimiter |
||
| 133 | * @param string|null $prefix |
||
| 134 | * @param string|null $suffix |
||
| 135 | * @return string |
||
| 136 | * @throws NotConvertibleToStringException |
||
| 137 | */ |
||
| 138 | public function joinToString(string $delimiter, string $prefix = null, string $suffix = null): string; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Alias for <code>count()</code> |
||
| 142 | * @return int |
||
| 143 | */ |
||
| 144 | public function size(): int; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Returns true if at least one element match the given predicate. |
||
| 148 | * |
||
| 149 | * @param callable $predicate f(item) -> bool |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | public function any(callable $predicate): bool; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Returns true if all element match the given predicate. |
||
| 156 | * |
||
| 157 | * @param callable $predicate f(item) -> bool |
||
| 158 | * @return bool |
||
| 159 | */ |
||
| 160 | public function all(callable $predicate): bool; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Splits this collection into a list of lists each not exceeding the given size. |
||
| 164 | * |
||
| 165 | * @param int $size |
||
| 166 | * @return ListInterface<ListInterface<mixed>> |
||
| 167 | */ |
||
| 168 | public function chunk(int $size): ListInterface; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Returns a list containing only distinct elements from the given array. |
||
| 172 | * |
||
| 173 | * @return ListInterface<mixed> |
||
| 174 | */ |
||
| 175 | public function distinct(): ListInterface; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param callable $action f(element: mixed) -> void|mixed |
||
| 179 | * @return void |
||
| 180 | */ |
||
| 181 | public function forEach(callable $action): void; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Returns an element at the given index or the result of calling the defaultValue |
||
| 185 | * function if the index is out of bounds of this list. |
||
| 186 | * |
||
| 187 | * @param int $index |
||
| 188 | * @param callable $defaultValue - f() -> mixed |
||
| 189 | * @return mixed |
||
| 190 | */ |
||
| 191 | public function getOrElse(int $index, callable $defaultValue); |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Returns a new list of this list between the specified fromIndex (inclusive) and toIndex (exclusive). |
||
| 195 | * |
||
| 196 | * @param int $fromIndex |
||
| 197 | * @param int $toIndex |
||
| 198 | * @return ListInterface |
||
| 199 | */ |
||
| 200 | public function subList(int $fromIndex, int $toIndex): ListInterface; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param callable $match |
||
| 204 | * @return mixed|null |
||
| 205 | */ |
||
| 206 | public function searchBy(callable $match); |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @return bool |
||
| 210 | */ |
||
| 211 | public function isEmpty(): bool; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | public function isNotEmpty(): bool; |
||
| 217 | } |
||
| 218 |