You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today I has a task that required me to pull some information from a collection, so later on I could assert that the collection was empty. It is quite simple if you think about it, but I couldn't figure out an elegant way to write it. Oh, one important detail is: I didn't know the keys to those information.
Initially I wrote something like $info = $collection->first(fn (item) => $item == $neededInfo); $collection = $collect->reject(fn (item) => $item == $neededInfo); and then changed it to a macro that did a search + get + forget and used it like $info = $collection->pullFirst(fn (item) => $item == $neededInfo);. But IMHO this approach still isn't great.
I read pretty much the whole Collections' doc but didn't find a simple way to do this. Wouldn't it be nice to have such a functionality? Or is it just me?
I want to finally start contributing to the project, but I think it'd be nice to get some opinions first.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
Today I has a task that required me to pull some information from a collection, so later on I could assert that the collection was empty. It is quite simple if you think about it, but I couldn't figure out an elegant way to write it. Oh, one important detail is: I didn't know the keys to those information.
Initially I wrote something like
$info = $collection->first(fn (item) => $item == $neededInfo); $collection = $collect->reject(fn (item) => $item == $neededInfo);
and then changed it to a macro that did asearch + get + forget
and used it like$info = $collection->pullFirst(fn (item) => $item == $neededInfo);
. But IMHO this approach still isn't great.I read pretty much the whole Collections' doc but didn't find a simple way to do this. Wouldn't it be nice to have such a functionality? Or is it just me?
I want to finally start contributing to the project, but I think it'd be nice to get some opinions first.
Beta Was this translation helpful? Give feedback.
All reactions