@@ 931-941 (lines=11) @@ | ||
928 | * @param array|Traversable $replacementMap |
|
929 | * @return Collection |
|
930 | */ |
|
931 | function replace($collection, $replacementMap) |
|
932 | { |
|
933 | $generatorFactory = function () use ($collection, $replacementMap) { |
|
934 | foreach ($collection as $key => $value) { |
|
935 | $newValue = getOrDefault($replacementMap, $value, $value); |
|
936 | yield $key => $newValue; |
|
937 | } |
|
938 | }; |
|
939 | ||
940 | return new Collection($generatorFactory); |
|
941 | } |
|
942 | ||
943 | /** |
|
944 | * Returns a lazy collection of reduction steps. |
|
@@ 1653-1663 (lines=11) @@ | ||
1650 | * @param array|Traversable $replacementMap |
|
1651 | * @return Collection |
|
1652 | */ |
|
1653 | function replaceByKeys($collection, $replacementMap) |
|
1654 | { |
|
1655 | $generatorFactory = function () use ($collection, $replacementMap) { |
|
1656 | foreach ($collection as $key => $value) { |
|
1657 | $newValue = getOrDefault($replacementMap, $key, $value); |
|
1658 | yield $key => $newValue; |
|
1659 | } |
|
1660 | }; |
|
1661 | ||
1662 | return new Collection($generatorFactory); |
|
1663 | } |
|
1664 | ||
1665 | /** |
|
1666 | * Dumps a variable into scalar or array (recursively). |