-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathAry.php
More file actions
40 lines (35 loc) · 930 Bytes
/
Copy pathAry.php
File metadata and controls
40 lines (35 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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;
/**
* Call $func with only abs($count) arguments, taken either from the
* left or right depending on the sign
*
* @template V
* @template T
*
* @param callable(T...):V $func
* @param non-zero-int $count
*
* @return callable(T...):V
*
* @no-named-arguments
*/
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 {
return $func(...take_right($args, -$count));
}
};
}