-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 sample for text version of find #5368
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,18 @@ class Strings { | |
assertPrints(matchDetails(inputString, toFind, 10), "Searching for 'ever' in 'Never ever give up' starting at position 10: Not found") | ||
} | ||
|
||
@Sample | ||
fun find() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sample is not compilable, please run it locally before submitting the updated version. |
||
val text = "k1o2t3l4i5n6" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a slightly more readable string, like |
||
|
||
val firstNumberInText = text.find { it.isDigit() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please inline an expression that uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it adds some context, but it might be better to add an explicit comment like |
||
val firstUpperCaseInText = text.find { it.isUpperCase() } | ||
|
||
|
||
assertPrints(firstNumberInText, "1") | ||
assertPrints(firstUpperCaseInText, null) | ||
} | ||
|
||
@Sample | ||
fun last() { | ||
val string = "Kotlin 1.4.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,7 +607,12 @@ object Elements : TemplateGroupBase() { | |
} builder { | ||
inline(Inline.Only) | ||
doc { "Returns the first ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } | ||
sample("samples.collections.Collections.Elements.find") | ||
specialFor(CharSequences) { | ||
sample("samples.text.Strings.find") | ||
} | ||
specialFor(ArraysOfUnsigned) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original
|
||
sample("samples.collections.Collections.Elements.find") | ||
} | ||
returns("T?") | ||
body { "return firstOrNull(predicate)"} | ||
} | ||
|
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.
@RohitGupta200 please make sure that these generated files are updated via
:tools:kotlin-stdlib-gen:run
command.See https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/ReadMe.md#code-generation for details.