|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Neo4j PHP Client and Driver package. |
| 7 | + * |
| 8 | + * (c) Nagels <https://nagels.tech> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Laudis\Neo4j\Contracts; |
| 15 | + |
| 16 | +use Countable; |
| 17 | +use Iterator; |
| 18 | +use JsonSerializable; |
| 19 | +use Laudis\Neo4j\Types\CypherList; |
| 20 | +use Laudis\Neo4j\Types\CypherMap; |
| 21 | +use Laudis\Neo4j\Types\Map; |
| 22 | + |
| 23 | +/** |
| 24 | + * Abstract immutable sequence with basic functional methods. |
| 25 | + * |
| 26 | + * @template TValue |
| 27 | + */ |
| 28 | +interface CypherSequence extends Countable, JsonSerializable |
| 29 | +{ |
| 30 | + /** |
| 31 | + * Copies the sequence. |
| 32 | + * |
| 33 | + * @return self<TValue> |
| 34 | + * |
| 35 | + * @psalm-mutation-free |
| 36 | + */ |
| 37 | + public function copy(): self; |
| 38 | + |
| 39 | + /** |
| 40 | + * Returns whether the sequence is empty. |
| 41 | + * |
| 42 | + * @psalm-suppress UnusedForeachValue |
| 43 | + */ |
| 44 | + public function isEmpty(): bool; |
| 45 | + |
| 46 | + /** |
| 47 | + * Creates a new sequence by merging this one with the provided iterable. When the iterable is not a list, the provided values will override the existing items in case of a key collision. |
| 48 | + * |
| 49 | + * @template NewValue |
| 50 | + * |
| 51 | + * @param iterable<mixed, NewValue> $values |
| 52 | + * |
| 53 | + * @return self<TValue|NewValue> |
| 54 | + * |
| 55 | + * @psalm-mutation-free |
| 56 | + */ |
| 57 | + public function merge(iterable $values): self; |
| 58 | + |
| 59 | + /** |
| 60 | + * Checks if the sequence contains the given key. |
| 61 | + */ |
| 62 | + public function hasKey(string|int $key): bool; |
| 63 | + |
| 64 | + /** |
| 65 | + * Checks if the sequence contains the given value. The equality check is strict. |
| 66 | + */ |
| 67 | + public function hasValue(mixed $value): bool; |
| 68 | + |
| 69 | + /** |
| 70 | + * Creates a filtered the sequence with the provided callback. |
| 71 | + * |
| 72 | + * @param callable(TValue, array-key):bool $callback |
| 73 | + * |
| 74 | + * @return self<TValue> |
| 75 | + * |
| 76 | + * @psalm-mutation-free |
| 77 | + */ |
| 78 | + public function filter(callable $callback): self; |
| 79 | + |
| 80 | + /** |
| 81 | + * Maps the values of this sequence to a new one with the provided callback. |
| 82 | + * |
| 83 | + * @template ReturnType |
| 84 | + * |
| 85 | + * @param callable(TValue, array-key):ReturnType $callback |
| 86 | + * |
| 87 | + * @return self<ReturnType> |
| 88 | + * |
| 89 | + * @psalm-mutation-free |
| 90 | + */ |
| 91 | + public function map(callable $callback): self; |
| 92 | + |
| 93 | + /** |
| 94 | + * Reduces this sequence with the given callback. |
| 95 | + * |
| 96 | + * @template TInitial |
| 97 | + * |
| 98 | + * @param TInitial|null $initial |
| 99 | + * @param callable(TInitial|null, TValue, array-key):TInitial $callback |
| 100 | + * |
| 101 | + * @return TInitial |
| 102 | + */ |
| 103 | + public function reduce(callable $callback, mixed $initial = null): mixed; |
| 104 | + |
| 105 | + /** |
| 106 | + * Finds the position of the value within the sequence. |
| 107 | + * |
| 108 | + * @return false|array-key returns the key of the value if it is found, false otherwise |
| 109 | + */ |
| 110 | + public function find(mixed $value): false|string|int; |
| 111 | + |
| 112 | + /** |
| 113 | + * Creates a reversed sequence. |
| 114 | + * |
| 115 | + * @return self<TValue> |
| 116 | + * |
| 117 | + * @psalm-mutation-free |
| 118 | + */ |
| 119 | + public function reversed(): self; |
| 120 | + |
| 121 | + /** |
| 122 | + * Slices a new sequence starting from the given offset with a certain length. |
| 123 | + * If the length is null it will slice the entire remainder starting from the offset. |
| 124 | + * |
| 125 | + * @return self<TValue> |
| 126 | + * |
| 127 | + * @psalm-mutation-free |
| 128 | + */ |
| 129 | + public function slice(int $offset, ?int $length = null): self; |
| 130 | + |
| 131 | + /** |
| 132 | + * Creates a sorted sequence. If the comparator is null it will use natural ordering. |
| 133 | + * |
| 134 | + * @param (callable(TValue, TValue):int)|null $comparator |
| 135 | + * |
| 136 | + * @return self<TValue> |
| 137 | + * |
| 138 | + * @psalm-mutation-free |
| 139 | + */ |
| 140 | + public function sorted(?callable $comparator = null): self; |
| 141 | + |
| 142 | + /** |
| 143 | + * Creates a list from the arrays and objects in the sequence whose values corresponding with the provided key. |
| 144 | + * |
| 145 | + * @return CypherList<mixed> |
| 146 | + * |
| 147 | + * @psalm-mutation-free |
| 148 | + */ |
| 149 | + public function pluck(string|int $key): CypherList; |
| 150 | + |
| 151 | + /** |
| 152 | + * Uses the values found at the provided key as the key for the new Map. |
| 153 | + * |
| 154 | + * @return CypherMap<mixed> |
| 155 | + * |
| 156 | + * @psalm-mutation-free |
| 157 | + */ |
| 158 | + public function keyBy(string|int $key): CypherMap; |
| 159 | + |
| 160 | + /** |
| 161 | + * Joins the values within the sequence together with the provided glue. If the glue is null, it will be an empty string. |
| 162 | + */ |
| 163 | + public function join(?string $glue = null): string; |
| 164 | + |
| 165 | + /** |
| 166 | + * Iterates over the sequence and applies the callable. |
| 167 | + * |
| 168 | + * @param callable(TValue, array-key):void $callable |
| 169 | + * |
| 170 | + * @return self<TValue> |
| 171 | + */ |
| 172 | + public function each(callable $callable): self; |
| 173 | + |
| 174 | + /** |
| 175 | + * Returns the sequence as an array. |
| 176 | + * |
| 177 | + * @return array<array-key, TValue> |
| 178 | + */ |
| 179 | + public function toArray(): array; |
| 180 | + |
| 181 | + /** |
| 182 | + * Returns the sequence as an array. |
| 183 | + * |
| 184 | + * @return array<array-key, TValue|array> |
| 185 | + */ |
| 186 | + public function toRecursiveArray(): array; |
| 187 | + |
| 188 | + /** |
| 189 | + * @return Iterator<array-key, TValue> |
| 190 | + */ |
| 191 | + public function getGenerator(): Iterator; |
| 192 | + |
| 193 | + /** |
| 194 | + * @return self<TValue> |
| 195 | + */ |
| 196 | + public function withCacheLimit(int $cacheLimit): self; |
| 197 | + |
| 198 | + /** |
| 199 | + * Preload the lazy evaluation. |
| 200 | + */ |
| 201 | + public function preload(): void; |
| 202 | + |
| 203 | + public function __serialize(): array; |
| 204 | +} |
0 commit comments