-
Notifications
You must be signed in to change notification settings - Fork 28
[Proposal] Add ->conjoin()
Method To Collection
#568
Comments
->add()
Method To Collection->inject()
Method To Collection
->inject()
Method To Collection->conjoin()
Method To Collection
What will happen if both have same index? |
@Dylan-DPC Well, if it is not overwriting like the existing method then it must... skip over it and keep the base collections value? |
Uhm. So you have $a and $b, and want to |
@Dylan-DPC @Garbee No, it adds all items, even if the indexes are the same, since push doesn't care about the content (whereas merge inspects the keys). I have implemented this in production already, and thought to share this here. Granted, its not a common use-case, as it only happens when mixing different types of objects in a collection that have the same id. @sisve Not really, because doing |
Ah, so you want to entirely ignore the keys and create a new collection of only the values. So a built-in way of doing |
Or you could also do |
@Garbee no, I don't want to ignore keys, I want to allow for duplicate keys, but different values. but good idea on not mutating, thanks :). Update: I see now what you meant with keys, sorry got that confused. Right, I am ignoring keys, and only adding objects. However, the merge function overwrites items if the numerical keys match. Using push just adds it to the end of the collection, ignoring the key. Adding this method would allow direct collection-to-collection manipulation, without having to iterate. |
PR was merged in. Thanks for the feedback everyone! :) Method was renamed to concat(). |
I would like to propose adding an
->conjoin($collection)
method that behaves similarly to->merge()
, but does not overwrite items with the same key. Please forgive me if this is already doable with a collection method, but I couldn't find one.Would be happy to write up a PR for this. Here's a sample of what I had in mind:
The text was updated successfully, but these errors were encountered: