private function rewind($traversable, $key)
    {
        if ($key === null) {
            return;
        }

        if (is_array($traversable)) {
            foreach ($traversable as $currentKey => $value) {
                if ($currentKey === $key) {
                    break;
                }
            }
        } else {
            $traversable->rewind();
            while ($traversable->valid() && $key !== $traversable->key()) {
                $traversable->next();
            }
        }
    }