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