-
Notifications
You must be signed in to change notification settings - Fork 6k
KT-20357: Add getOrElse sample for Collections #5482
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
Conversation
c033094
to
ccd949a
Compare
ccd949a
to
045cbe0
Compare
@@ -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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
Merged: 53be3ba |
Added a sample function for
getOrElse
inCollections
.There was already a sample for
Map
, but none forCollections
.Related issue: https://youtrack.jetbrains.com/issue/KT-20357