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