Skip to content

Conversation

hondaya14
Copy link

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
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.

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

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

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