public function takeWhileWithIndex(callable $predicate) { $index = 0; return $this->takeWhile(function ($value) use($predicate, &$index) { return call_user_func_array($predicate, [$index++, $value]); }); }