1 | <?php |
||
12 | class Collection implements Iterator |
||
13 | { |
||
14 | use CollectionTrait; |
||
15 | |||
16 | /** |
||
17 | * @var Iterator |
||
18 | */ |
||
19 | protected $input; |
||
20 | |||
21 | /** |
||
22 | * @var callable |
||
23 | */ |
||
24 | private $generatorFactory; |
||
25 | |||
26 | /** |
||
27 | * @param callable|Closure|array|Traversable $input If callable is passed, it must be a generator factory function |
||
28 | */ |
||
29 | 78 | public function __construct($input) |
|
46 | |||
47 | /** |
||
48 | * Static alias of normal constructor. |
||
49 | * |
||
50 | * @param array|Traversable $input |
||
51 | * @return Collection |
||
52 | */ |
||
53 | 4 | public static function from($input) |
|
57 | |||
58 | /** |
||
59 | * Returns lazy collection of values, where first value is $input and all subsequent values are computed by applying |
||
60 | * $function to the last value in the collection. By default this produces an infinite collection. However you can |
||
61 | * end the collection by throwing a NoMoreItems exception. |
||
62 | * |
||
63 | * @param mixed $input |
||
64 | * @param callable $function |
||
65 | * @return Collection |
||
66 | */ |
||
67 | 2 | public static function iterate($input, callable $function) |
|
71 | |||
72 | /** |
||
73 | * Returns a lazy collection of $value repeated $times times. If $times is not provided the collection is infinite. |
||
74 | * |
||
75 | * @param mixed $value |
||
76 | * @param int $times |
||
77 | * @return Collection |
||
78 | */ |
||
79 | 3 | public static function repeat($value, $times = -1) |
|
83 | |||
84 | /** |
||
85 | * Returns a lazy collection of numbers starting at $start, incremented by $step until $end is reached. |
||
86 | * |
||
87 | * @param int $start |
||
88 | * @param int|null $end |
||
89 | * @param int $step |
||
90 | * @return Collection |
||
91 | */ |
||
92 | 2 | public static function range($start = 0, $end = null, $step = 1) |
|
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | 73 | public function current() |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 72 | public function next() |
|
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | 71 | public function key() |
|
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | 76 | public function valid() |
|
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | 76 | public function rewind() |
|
140 | } |
||
141 |