1 | <?php |
||
12 | class IteratorTools |
||
13 | { |
||
14 | /** |
||
15 | * Ensures that the given items are \Traversable. |
||
16 | * |
||
17 | * Usage: |
||
18 | * |
||
19 | * ``` |
||
20 | * IteratorTools::ensureTraversable([1, 2, 3]); |
||
21 | * IteratorTools::ensureTraversable(new \ArrayIterator([1, 2, 3])); |
||
22 | * ``` |
||
23 | * |
||
24 | * @param mixed $items |
||
25 | * |
||
26 | * @throws \InvalidArgumentException |
||
27 | */ |
||
28 | public static function ensureTraversable($items): \Traversable |
||
40 | |||
41 | /** |
||
42 | * Creates an iterator from an array. |
||
43 | * |
||
44 | * Usage: |
||
45 | * |
||
46 | * ``` |
||
47 | * IteratorTools::fromArray([1, 2, 3]); |
||
48 | * ``` |
||
49 | * |
||
50 | * @param array $results |
||
51 | */ |
||
52 | public static function fromArray(array $results): \Traversable |
||
56 | |||
57 | /** |
||
58 | * Creates an iterator from a generator. |
||
59 | * |
||
60 | * Example of valid usage: |
||
61 | * |
||
62 | * ``` |
||
63 | * IteratorTools::fromGenerator(function() { |
||
64 | * yield 1; |
||
65 | * yield 2; |
||
66 | * yield 3; |
||
67 | * }); |
||
68 | * ``` |
||
69 | * |
||
70 | * @param callable $generatorCallable A callable, which will return a generator once called. |
||
71 | */ |
||
72 | public static function fromGenerator(callable $generatorCallable): \Traversable |
||
76 | } |
||
77 |