1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Iterator;
4:
5: use Salient\Contract\Core\Arrayable;
6: use Traversable;
7:
8: /**
9: * An iterator with a fluent interface
10: *
11: * @template TKey of array-key
12: * @template TValue
13: *
14: * @extends Arrayable<TKey|int,TValue>
15: * @extends Traversable<TKey,TValue>
16: */
17: interface FluentIteratorInterface extends Arrayable, Traversable
18: {
19: /**
20: * Copy the iterator's elements to an array
21: *
22: * @return ($preserveKeys is true ? array<TKey,TValue> : list<TValue>)
23: */
24: public function toArray(bool $preserveKeys = true): array;
25:
26: /**
27: * Apply a callback to the iterator's elements
28: *
29: * @param callable(TValue, TKey): mixed $callback
30: * @return $this
31: */
32: public function forEach(callable $callback);
33:
34: /**
35: * Get the value of the iterator's first element with a key or property
36: * equal to a given value
37: *
38: * @param array-key $key
39: * @param mixed $value
40: * @return TValue|null `null` if no matching element is found.
41: */
42: public function nextWithValue($key, $value, bool $strict = false);
43: }
44: