Return an iterator for the given collection if
possible.

@param $xs
@return \ArrayIterator
@throws \InvalidArgumentException
167133
public static function iterator($xs)
    {
        if (is_array($xs)) {
            return new \ArrayIterator($xs);
        }
        if (!$xs instanceof \Iterator) {
            throw new \InvalidArgumentException();
        }
        return $xs;
    }
766553
public function getIterator()
    {
    	if ($this->sortedIterator === null) {
    	    if ($this->cloneItems) {
    	        $array = array();
                foreach ($this->originalIterator as $key => $value) {
                    $array[$key] = clone $value;
                }
            } else {
    	        $array = iterator_to_array($this->originalIterator);
    	    }
    	    $this->sort($array);
    	    $this->sortedIterator = new \ArrayIterator($array);
    	}
    	return $this->sortedIterator;
    }
1065544
public function getIterator()
    {
        $tagsById       = $this->container->findTaggedServiceIds($this->tag);
        $taggedServices = array();
        foreach ($tagsById as $id => $tagDefinitions) {
            /* @var $id string */
            /* @var $tagDefinitions array(array(string=>string)) */
            foreach ($tagDefinitions as $tagDefinition) {
                /* @var $tagDefinition array(string=>string) */
                $taggedServices[] = new TaggedService($id, $tagDefinition);
            }
        }
        return new \ArrayIterator($taggedServices);
    }
429268
public function getIterator(): \Traversable
    {
        $routes = $this->routes;
        usort(
                $routes,
                function(Route $a, Route $b)
                {
                    return strnatcmp($a->configuredPath(), $b->configuredPath());
                }
        );
        return new \ArrayIterator($routes);
    }
520926
public static function factory($aOptions){
		if($aOptions instanceof \Traversable)$aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
		elseif(!is_array($aOptions))throw new \InvalidArgumentException(__METHOD__.' expects an array or Traversable object; received "'.(is_object($aOptions)?get_class($aOptions):gettype($aOptions)).'"');
		return new static(new \TreeLayoutStack\TemplatingConfiguration($aOptions));
	}
8135
public function getIterator()
    {
        $array = [];
        foreach (array_keys($this->imports) as $group) {
            $array[$group] = $this->offsetGet($group);
        }

        return new ArrayIterator($array);
    }
131361
public static function reciprocal(array $xs): array
    {
        $zeros = array_filter(
            $xs,
            function (float $x) {
                return $x == 0;
            }
        );
        if (!empty($zeros)) {
            throw new Exception\BadDataException('Cannot compute the reciprocal of 0');
        }

        return array_map(
            function ($x) {
                return 1 / $x;
            },
            $xs
        );
    }
23178
public function getIterator($ns = 'BackBee\\Console\\Command')
    {
        if (null === $this->container) {
            throw new \LogicException('You must call setContainer() before iterating over this finder.');
        }
        $iterator = parent::getIterator();

        $result = new \ArrayIterator();
        foreach ($iterator as $file) {
            if ($relativePath = $file->getRelativePath()) {
                $ns .= '\\'.strtr($relativePath, '/', '\\');
            }

            $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
            if (
                $r->isSubclassOf('BackBee\\Console\\AbstractCommand')
                && !$r->isAbstract()
                && !$r->getConstructor()->getNumberOfRequiredParameters()
            ) {
                $result->append($r->newInstance());
            }
        }

        return $result;
    }
193701
private function createFilesIterator(string ...$paths): Iterator
    {
        return new ArrayIterator(
            array_map(
                function (string $path) : SplFileInfo {
                    return new SplFileInfo($path);
                },
                array_filter(
                    $paths,
                    function (string $path) : bool {
                        return is_readable($path);
                    }
                )
            )
        );
    }
139849
public function getIterator()
    {
        if (!is_null($this->iterator)) {
            return $this->iterator;
        }

        return $this->iterator = new ArrayIterator((array) $this->value);
    }
875370
public function getIterator()
    {
        $items = array_map(
            function ($item) {
                return is_array($item) ? new ArrayData($item) : $item;
            },
            $this->items
        );
        return new ArrayIterator($items);
    }
897474
public function getIterator()
    {
        $data = $this->data;
        foreach ($this->data as $key => $val) {
            $data[$key] = $this->extractKey($key);
        }
        return new \ArrayIterator($data);
    }
102572
public static function fromCollection($collection) {
		if (!(is_array($collection) || $collection instanceof Iterator)) {
			throw new InvalidArgumentException('$collection is neither an array nor an iterator');
		}

		return self::toCollection($collection);
	}
1041557
private static function AtomizeIterator( $iter )
	{
		/**
		 * @var XPathNavigator $item
		 */
		foreach ( $iter as $item )
		{
			if ( $item->getIsNode() )
			{
				if ( $item->getNodeType() == XPathNodeType::Comment )
				{
					continue;
				}

				if ( $item->getNodeType() == XPathNodeType::Element )
				{
					$child = $item->CloneInstance();
					$result = $child->MoveToFirstChild();

					$items = array();

					if ( $child->getNodeType() == XPathNodeType::Text )
					{
						$items[] = $item->getTypedValue();
					}
					else
					{
						while ( $result )
						{
							$data = ExtFuncs::GetData( XPath2NodeIterator::Create( $child->CloneInstance() ) );
							if ( $data->MoveNext() )
							{
								$items[] = $data->getCurrent(); // ->getValue();
							}

							$result = $child->MoveToNext();
						}
					}

					if ( ! count( $items ) )
					{
						yield Undefined::getValue();
					}
					else if ( count( $items ) == 1 )
					{
						yield $items[0];
					}
					else
					{
						yield XPath2Item::fromValueAndType( implode( "", $items ), XmlSchema::$String );
					}

					return false;
				}
				else
				if ( is_null( $item->getTypedValue() ) )
				{
			    	if ( $item instanceof XPathNavigator )
					{
						/**
						 * @var XPathNavigator $nav
						 */
						$nav = $item;
						if ( ! is_null( $nav->getSchemaInfo() ) &&
							 ! is_null( $nav->getSchemaInfo()->getSchemaType() ) &&
							 ! ( $nav->getSchemaInfo()->getSchemaType() instanceof XmlSchemaSimpleType ) )
						{
							throw XPath2Exception::withErrorCodeAndParam( "FOTY0012", Resources::FOTY0012, new XmlQualifiedName( $nav->LocalName, $nav->NamespaceURI, false ) );
						}
					}
				}
			}

		    yield $item instanceof XPath2Item
		    	? $item
		    	: XPath2Item::fromValue( $item->GetTypedValue() );
		}
	}
660346
public function getIterator(): \Traversable
    {
        if ($this->data instanceof \ArrayIterator) {
            return $this->data;
        }

        if ($this->data instanceof \IteratorAggregate) {
            return $this->data->getIterator();
        }

        if (!\is_array($this->data)) {
            throw new NotIterableException('Cannot get iterator for data');
        }

        return new \ArrayIterator($this->data);
    }
59604
public static function max(array $xs, $value): array
    {
        return array_map(
            function ($x) use ($value) {
                return max($x, $value);
            },
            $xs
        );
    }
947855
public function getFlyIterator($flags=null)
    {
        if (is_null($flags)) {
            $flags = self::ITERATOR_DIRECTORY | self::ITERATOR_FILE;
        }

        $recursive = ($flags & self::ITERATOR_RECURSIVE);
        $withDirectories = ($flags & self::ITERATOR_DIRECTORY);
        $withFiles = ($flags & self::ITERATOR_FILE);

        $iterator = array();
        $contents = $this->getFileSystem()->listContents($this->getPrefix(), $recursive);

        foreach ($contents as $content) {
            if ($withDirectories && $content['type'] == 'dir') {
                $iterator[] = $this->getDirectory(str_replace($this->getPrefix(), '', $content['path']));
            }

            if ($withFiles && $content['type'] == 'file') {
                $iterator[] = $this->getFile(str_replace($this->getPrefix(), '', $content['path']));
            }
        }

        return new \ArrayIterator($iterator);
    }