|
@@ 1270-1282 (lines=13) @@
|
| 1267 |
|
* @param array|Traversable ...$collections |
| 1268 |
|
* @return Collection |
| 1269 |
|
*/ |
| 1270 |
|
function diff($collection, ...$collections) |
| 1271 |
|
{ |
| 1272 |
|
$valuesToCompare = toArray(values(concat(...$collections))); |
| 1273 |
|
$generatorFactory = function () use ($collection, $valuesToCompare) { |
| 1274 |
|
foreach ($collection as $key => $value) { |
| 1275 |
|
if (!in_array($value, $valuesToCompare)) { |
| 1276 |
|
yield $key => $value; |
| 1277 |
|
} |
| 1278 |
|
} |
| 1279 |
|
}; |
| 1280 |
|
|
| 1281 |
|
return new Collection($generatorFactory); |
| 1282 |
|
} |
| 1283 |
|
|
| 1284 |
|
/** |
| 1285 |
|
* Returns a lazy collection of items that are in $collection and all the other arguments, indexed by the keys from the |
|
@@ 1292-1304 (lines=13) @@
|
| 1289 |
|
* @param array|Traversable ...$collections |
| 1290 |
|
* @return Collection |
| 1291 |
|
*/ |
| 1292 |
|
function intersect($collection, ...$collections) |
| 1293 |
|
{ |
| 1294 |
|
$valuesToCompare = toArray(values(concat(...$collections))); |
| 1295 |
|
$generatorFactory = function () use ($collection, $valuesToCompare) { |
| 1296 |
|
foreach ($collection as $key => $value) { |
| 1297 |
|
if (in_array($value, $valuesToCompare)) { |
| 1298 |
|
yield $key => $value; |
| 1299 |
|
} |
| 1300 |
|
} |
| 1301 |
|
}; |
| 1302 |
|
|
| 1303 |
|
return new Collection($generatorFactory); |
| 1304 |
|
} |
| 1305 |
|
|
| 1306 |
|
/** |
| 1307 |
|
* Returns a lazy collection where keys and values are flipped. |