-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathdiff.php
43 lines (37 loc) · 833 Bytes
/
diff.php
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
41
42
43
<?php
declare(strict_types=1);
namespace Psl\Dict;
use Psl\Iter;
use Psl\Vec;
use function array_diff;
/**
* Computes the difference of iterables.
*
* @template Tk of array-key
* @template Tv
*
* @param iterable<Tk, Tv> $first
* @param iterable<Tk, Tv> $second
* @param iterable<Tk, Tv> ...$rest
*
* @return array<Tk, Tv>
*/
function diff(iterable $first, iterable $second, iterable ...$rest): array
{
if (Iter\is_empty($first)) {
return [];
}
return array_diff(
from_iterable($first),
from_iterable($second),
...Vec\map(
$rest,
/**
* @param iterable<Tk, Tv> $iterable
*
* @return array<Tk, Tv>
*/
static fn(iterable $iterable): array => from_iterable($iterable),
),
);
}