-
-
Notifications
You must be signed in to change notification settings - Fork 186
Add $collection->join() #7340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add $collection->join() #7340
Conversation
|
I would expect that a collection method called |
|
|
I think it makes sense since we already have |
|
Fair. @adamkiss Would you be able to fix the two code style errors? |
|
@distantnative yeah |
|
Sorry for delay but I just wonder why we used empty separator for for collection join but we used comma for arrays? public static function join(
array|string $value,
string $separator = ', '
): string {
if (is_string($value) === true) {
return $value;
}
return implode($separator, $value);
} |
|
@afbora I think you are right and it makes sense to stay consistent there. Probably should also stick to |
|
@afbora @distantnative Because while I understand why you thought joining array items vas imagined with some kind of tags or something, where commas might be preferable, I think major usage of collection (pages, users) join is html output, where no extraneous elements are wanted. I think it's better to keep it empty, but settable, rather than default to comma and force every html output usage to unset it |
|
@adamkiss I disagree, I think you are coming from a very specific use case in mind. But joining a collection doesn't have to be about HTML output (in fact I think your example use case with the snippet is more an outlier), e.g. $venues = $events->join(as: fn ($event) => $event->venue());I think it does make sense to keep |
|
I don't think it's a big deal. Because both spaces and commas can be used in different use cases. But it would be nice to have consistency. |
|
@distantnative I'm not saying it's impossible to come up with a different use case, but I wholeheartedly think that
Thus consistency in the direction of default value is IMO detrimental to the major workflow @afbora the default I set isn't a space, it's nothing, just putting the outputs together |
|
@adamkiss Agree to disagree here. Consistency has a super high value with a framework tool like Kirby - we can tell how it bites us every time we aren't consistent as it defies user expectations. The Collection class is such a general tool, to me it doesn't make sense to add a narrower use-case of HTML (this is where we will disagree) as default, trading off with consistency. |
What I meant by "space" was the spaceless 🙂 Beyond consistency, if I wanted to join a collection or array to a string, I would think it would need a separator to make it readable. So, unlike you, I personally think users would prefer commas. |
Description
Adds a method to join collection into a string, supporting mapping and custom glue.
Helps to simplify mapping and joining a collection:
Summary of changes
Reasoning
Ready?
For review team