HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/beerten.komma.nl/vendor/lstrojny/functional-php/src/Functional/Ary.php
<?php

/**
 * @package   Functional-php
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Hugo Sales
 * @license   https://opensource.org/licenses/MIT MIT
 * @link      https://github.com/lstrojny/functional-php
 */

namespace Functional;

use Functional\Exceptions\InvalidArgumentException;
use Traversable;

/**
 * Call $func with only abs($count) arguments, taken either from the
 * left or right depending on the sign
 */
function ary(callable $func, int $count): callable
{
    InvalidArgumentException::assertNonZeroInteger($count, __FUNCTION__);

    return function (...$args) use ($func, $count) {
        if ($count > 0) {
            return $func(...take_left($args, $count));
        } else if ($count < 0) {
            return $func(...take_right($args, -$count));
        }
    };
}