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