-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ignore_args
which ignores arguments over the supplied number
Added function which defines a function of an arbitry number of arguments and calls the provided callable with only the given number of arguments
- Loading branch information
1 parent
a736d25
commit a019437
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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 | ||
*/ | ||
public static function ingore_args(callable $func, int $count): callable | ||
{ | ||
return function (...$args) use ($func, $count) { | ||
if ($count > 0) { | ||
return call_user_func_array($func, take_left($args, $count)); | ||
} | ||
return call_user_func_array($func, take_right($args, -$count)); | ||
}; | ||
} |