Skip to content

ArrayExtension preserves keys#7

Open
mecha wants to merge 4 commits into0.1.xfrom
fix/array-extension-keys
Open

ArrayExtension preserves keys#7
mecha wants to merge 4 commits into0.1.xfrom
fix/array-extension-keys

Conversation

@mecha
Copy link
Member

@mecha mecha commented Jun 22, 2021

Fixes #6

@mecha mecha added the bug Something isn't working label Jun 22, 2021
@mecha mecha requested a review from XedinUnknown June 22, 2021 12:31
@mecha mecha self-assigned this Jun 22, 2021
@XedinUnknown
Copy link
Member

Is this really better than just array_map()?

Not quite sure. Maybe, resolveDeps() should return a map with keys preserved, and it's just a matter of array_values() to turn it into function args?

@mecha
Copy link
Member Author

mecha commented Jun 24, 2021

That would work. I wanted to keep the current resolveDeps() because I can see its utility. Given ["foo", "bar"] it returns ["foo" => ..., "bar" => ...], which makes a lot of sense. This is why I added a new method. A consumer may want to access the services by their key after passing them through resolveDeps().

On the other hand, there is nothing that is currently utilizing the service keys in the resolveDeps() return value. And realistically, there may not be. Given that this trait is used for service helpers, it's unlikely that individual services will be extracted from the returned array. So it could be changed to preserve the keys in the argument array.

But if we're going to do that, I think we could just use array_map. The immediately-invoked function and the creation of a Generator becomes obsolete and unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrayExtension does not preserve keys

2 participants