public static function getGeneratorElements(Generator $generator)
    {
        $elements = [];

        for (; $generator->valid(); $generator->next()) {
            $elements[] = $generator->current();
        }

        return $elements;
    }