Returns a subset of an array.

@see https://docs.mongodb.org/manual/reference/operator/aggregation/slice/
@see Expr::slice
@param mixed|Expr $array
@param mixed|Expr $n
@param mixed|Expr|null $position
@return $this

@since 1.3
13851
public function slice($array, $n, $position = null)
    {
        $this->expr->slice($array, $n, $position);

        return $this;
    }
679579
public function mergeRecursive($array)
    {
        if ($this->isInstanceOf($array, $this)) {
            $array = $array->val();
        }

        $this->val(array_merge_recursive($this->val(), $array));

        return $this;
    }
1331751
public function addGroup(string $name, int $position = null): Item
	{
		return $this->addItem(new Group($name), $position);
	}
1285013
function only ($n)
  {
    $this->setIterator ($it = new LoopIterator ($this->getIterator ()));
    $it->limit ($n);
    return $this;
  }
369185
protected function getPotential($position, $top, $sliceSize)
    {
        $safeZoneList = $this->getSafeZoneList();

        $safeRatio = 0;

        if ($position == 'top' || $position == 'left') {
            $start = $top;
            $end = $top + $sliceSize;
        } else {
            $start = $top - $sliceSize;
            $end = $top;
        }

        for ($i = $start; $i < $end; $i++) {
            foreach ($safeZoneList as $safeZone) {
                if ($position == 'top' || $position == 'bottom') {
                    if ($safeZone['top'] <= $i && $safeZone['bottom'] >= $i) {
                        $safeRatio = max($safeRatio, ($safeZone['right'] - $safeZone['left']));
                    }
                } else {
                    if ($safeZone['left'] <= $i && $safeZone['right'] >= $i) {
                        $safeRatio = max($safeRatio, ($safeZone['bottom'] - $safeZone['top']));
                    }
                }
            }
        }

        return $safeRatio;
    }
22602
public function slice($offset, $limit = null, $keys = true)
    {
        return new static(\array_slice($this->items, $offset, $limit, $keys));
    }
212514
public static <T> T access(T[] array, int n) {
        int max = array.length - 1;
        if ((n < 0) || (n > max)) {
            throw new InvalidValueException(n, "n", Range.between(0, max));
        }
        return array[n];
    }
322569
public static boolean get(boolean[] array, int position) {
        return !(position < 0 || position >= Utils.sizeOf(array)) && array[position];
    }
606860
public function slice(int $offset, ?int $length = null): ArrayCollection
    {
        return new static(array_slice($this->items, $offset, $length, true));
    }
374028
public function initial($collection=null, $n=null) {
    list($collection, $n) = self::_wrapArgs(func_get_args(), 2);
    
    $collection = (array) self::_collection($collection);
    
    if(is_null($n)) $n = 1;
    $first_index = count($collection) - $n;
    $__ = new self;
    return self::_wrap($__->first($collection, $first_index));
  }
856666
public function slice(int $offset, int $length = null):ByteArray{

		// keep an extended class
		/** @var \chillerlan\Traits\ArrayHelpers\ByteArray $slice */
		$slice  = (new ReflectionClass($this))->newInstanceArgs([$length ?? ($this->count() - $offset)]);

		foreach($slice as $i => $_){
			$slice[$i] = $this[$offset + $i];
		}

		return $slice;
	}
1046667
public function slice(int $offset, ?int $length = null): self
    {
        return Factory::create(\array_slice($this->items, $offset, $length, true));
    }
1120343
public function setItemPosition($position)
    {
        if ((int)$position >= 0) {
            // check if given position is larger as possible position
            if ($position >= ($countItems = $this->countItems())) {
                // set position to max possible position
                $position = $countItems - 1;
            }

            if ($position <= ($this->countItems() / 2)) {
                $this->getIteratorObject()->rewind();
                if (($countItems = $this->countItems()) > 0) {
                    $this->_itemPosition = $countItems - 1;
                } else {
                    $this->_itemPosition = 0;
                }

                // go with next
                while ($position != $this->_itemPosition) {
                    $this->getIteratorObject()->next();

                    if (!$this->getIteratorObject()->valid()) {
                        throw new IteratorDecoratorReverseException('Specified position is not valid (next).', E_NOTICE);
                        break;
                    } else {
                        $this->_itemPosition--;
                    }
                }
            } else {
                $this->getIteratorObject()->last();

                if (!$this->getIteratorObject()->valid()) {
                    $this->_itemPosition = 0;
                } else {
                    $this->_itemPosition = 0;
                }

                // go with prev
                while ($position != $this->_itemPosition) {
                    $this->getIteratorObject()->previous();

                    if (!$this->getIteratorObject()->valid()) {
                        throw new IteratorDecoratorReverseException('Specified position is not valid (previous).', E_NOTICE);
                        break;
                    } else {
                        $this->_itemPosition++;
                    }
                }
            }
        } else {
            throw new IteratorDecoratorReverseException('Specified position is not valid.', E_WARNING);
        }
    }
1036513
public function fromArray( array $list )
	{
		$unknown = array();
		$list = parent::fromArray( $list );

		foreach( $list as $key => $value )
		{
			switch( $key )
			{
				case $this->_prefix . 'refid': $this->setRefId( $value ); break;
				case $this->_prefix . 'position': $this->setPosition( $value ); break;
				default: $unknown[$key] = $value;
			}
		}

		return $unknown;
	}
332622
public function slice($offset, $length = null) {
      $this->items = array_slice($this->items, $offset, $length);
      return $this;
    }
1079245
private function delete(int $position)
    {
        $pair  = $this->pairs[$position];
        $value = $pair->value;

        array_splice($this->pairs, $position, 1, null);
        $this->checkCapacity();

        return $value;
    }
1075162
public function removeAt($position)
    {
        if (!is_numeric($position) || $position < 0) {
            throw new \InvalidArgumentException();
        }

        if ($position < count($this->items)) {
            array_splice($this->items, $position, 1);
        }

        $this->isUpdated = true;

        return $this;
    }