| @@ 2054-2075 (lines=22) @@ | ||
| 2051 | * @psalm-return static<TKey,T> |
|
| 2052 | * @psalm-mutation-free |
|
| 2053 | */ |
|
| 2054 | public function diff(array ...$array): self |
|
| 2055 | { |
|
| 2056 | if (\count($array) > 1) { |
|
| 2057 | $array = \array_merge([], ...$array); |
|
| 2058 | } else { |
|
| 2059 | $array = $array[0]; |
|
| 2060 | } |
|
| 2061 | ||
| 2062 | $generator = function () use ($array): \Generator { |
|
| 2063 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2064 | if (\in_array($value, $array, true) === false) { |
|
| 2065 | yield $key => $value; |
|
| 2066 | } |
|
| 2067 | } |
|
| 2068 | }; |
|
| 2069 | ||
| 2070 | return static::create( |
|
| 2071 | $generator, |
|
| 2072 | $this->iteratorClass, |
|
| 2073 | false |
|
| 2074 | ); |
|
| 2075 | } |
|
| 2076 | ||
| 2077 | /** |
|
| 2078 | * Return elements where the keys are only in the current array. |
|
| @@ 2089-2110 (lines=22) @@ | ||
| 2086 | * @psalm-return static<TKey,T> |
|
| 2087 | * @psalm-mutation-free |
|
| 2088 | */ |
|
| 2089 | public function diffKey(array ...$array): self |
|
| 2090 | { |
|
| 2091 | if (\count($array) > 1) { |
|
| 2092 | $array = \array_replace([], ...$array); |
|
| 2093 | } else { |
|
| 2094 | $array = $array[0]; |
|
| 2095 | } |
|
| 2096 | ||
| 2097 | $generator = function () use ($array): \Generator { |
|
| 2098 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2099 | if (\array_key_exists($key, $array) === false) { |
|
| 2100 | yield $key => $value; |
|
| 2101 | } |
|
| 2102 | } |
|
| 2103 | }; |
|
| 2104 | ||
| 2105 | return static::create( |
|
| 2106 | $generator, |
|
| 2107 | $this->iteratorClass, |
|
| 2108 | false |
|
| 2109 | ); |
|
| 2110 | } |
|
| 2111 | ||
| 2112 | /** |
|
| 2113 | * Return elements where the values and keys are only in the current array. |
|