Create clear, comprehensive, and properly structured code samples to document API usage. Follow these principles: 1. **Organize samples properly:** - Place samples after doc blocks
Create clear, comprehensive, and properly structured code samples to document API usage. Follow these principles:
sample("samples.collections.Collections.Elements.find")
specialFor(CharSequences) {
sample("samples.text.Strings.find")
}
@Sample fun substringWithRange() { // Overload with range val str = “abcde” assertPrints(str.substring(0, 3), “abc”) assertPrints(str.substring(0, 0), “”) } ```
@Sample
fun lastIndexOf() {
val inputString = "Never ever give up"
val toFind = "ever"
// Basic usage from start
assertPrints(inputString.lastIndexOf(toFind), "6")
// With specific start position
assertPrints(inputString.lastIndexOf(toFind, 5), "6")
// Start position after all occurrences
assertFails { inputString.lastIndexOf(toFind, 10) } // No occurrence after position 10
}
assertPrints()
which converts to readable documentation output
// This:
assertPrints(value, "stringRepresentation")
// Converts to:
println(value) // stringRepresentation
@sample
tags to all relevant function variants, including expect/actual declarationsEnter the URL of a public GitHub repository