Skip to content

Conversation

hondaya14
Copy link
Contributor

Added a sample function for getOrElse in Collections.
There was already a sample for Map, but none for Collections.

Related issue: https://youtrack.jetbrains.com/issue/KT-20357

@fzhinkin fzhinkin self-assigned this Aug 11, 2025
@fzhinkin fzhinkin added the Standard Library Sample Pull request with samples for stdlib API label Aug 11, 2025
@@ -1467,6 +1467,8 @@ public inline fun CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? {

/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrElse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to provide dedicated samples for array types (like it was done for contentEquals, for example: 658323f)

Copy link
Contributor Author

@hondaya14 hondaya14 Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added samples for array types. I opted not to introduce per-type methods (e.g. contentEquals), since that would be verbose and slightly reduce readability.
(ref: bdcf70b)

I’m unsure about the class structure—especially the sample subclass categorization—so I may be mistaken. Feedback would be appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted not to introduce per-type methods (e.g. contentEquals), since that would be verbose and slightly reduce readability.

That's fine, thanks. We discussed it with colleagues and decided to stick to this approach for now.

@hondaya14 hondaya14 requested a review from fzhinkin August 15, 2025 04:53
@hondaya14
Copy link
Contributor Author

@fzhinkin
When convenient, could you please re-review this? There’s no urgency; I just wanted to keep it on your radar. Thanks.

Copy link
Contributor

@fzhinkin fzhinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. There a few minor improvements to do, but otherwise it's almost ready for merge.

@@ -1467,6 +1467,8 @@ public inline fun CharArray.firstOrNull(predicate: (Char) -> Boolean): Char? {

/**
* Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
*
* @sample samples.collections.Collections.Elements.getOrElse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted not to introduce per-type methods (e.g. contentEquals), since that would be verbose and slightly reduce readability.

That's fine, thanks. We discussed it with colleagues and decided to stick to this approach for now.

fzhinkin
fzhinkin previously approved these changes Sep 9, 2025
@fzhinkin fzhinkin self-requested a review September 9, 2025 20:59
@fzhinkin
Copy link
Contributor

Merged: 53be3ba

@fzhinkin fzhinkin closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Standard Library Sample Pull request with samples for stdlib API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants