-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathCapture.php
More file actions
32 lines (28 loc) · 698 Bytes
/
Copy pathCapture.php
File metadata and controls
32 lines (28 loc) · 698 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
<?php
/**
* @package Functional-php
* @author Lars Strojny <lstrojny@php.net>
* @copyright 2011-2021 Lars Strojny
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/lstrojny/functional-php
*/
namespace Functional;
/**
* Return a new function that captures the return value of $callback in $result and returns the callback's return value
*
* @template T
*
* @param callable():T $callback
* @param T $result
*
* @return callable():T
*
* @no-named-arguments
*/
function capture(callable $callback, &$result)
{
return function (...$args) use ($callback, &$result) {
$result = $callback(...$args);
return $result;
};
}