Add samples for last() and lastOrNull() functions
This commit is contained in:
committed by
Abduqodiri Qurbonzoda
parent
e83a3c3f27
commit
ebdd023633
@@ -5,6 +5,8 @@
|
||||
|
||||
package templates
|
||||
|
||||
import templates.DocExtensions.collection
|
||||
import templates.DocExtensions.element
|
||||
import templates.Family.*
|
||||
import templates.SequenceClass.*
|
||||
|
||||
@@ -567,13 +569,19 @@ object Elements : TemplateGroupBase() {
|
||||
body { "return firstOrNull(predicate)"}
|
||||
}
|
||||
|
||||
private val Family.sampleClass: String
|
||||
get() = when (this) {
|
||||
Strings, CharSequences -> "samples.text.Strings"
|
||||
else -> "samples.collections.Collections.Elements"
|
||||
}
|
||||
|
||||
val f_last = fn("last()") {
|
||||
includeDefault()
|
||||
include(CharSequences, Lists, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { """Returns the last ${f.element}.
|
||||
@throws [NoSuchElementException] if the ${f.collection} is empty.""" }
|
||||
doc { "Returns the last ${f.element}." }
|
||||
throws("NoSuchElementException", "if the ${f.collection} is empty.")
|
||||
sample("${f.sampleClass}.last")
|
||||
returns("T")
|
||||
body {
|
||||
"""
|
||||
@@ -621,6 +629,7 @@ object Elements : TemplateGroupBase() {
|
||||
include(Lists, CharSequences, ArraysOfUnsigned)
|
||||
} builder {
|
||||
doc { "Returns the last ${f.element}, or `null` if the ${f.collection} is empty." }
|
||||
sample("${f.sampleClass}.last")
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
@@ -668,8 +677,9 @@ object Elements : TemplateGroupBase() {
|
||||
inline()
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { """Returns the last ${f.element} matching the given [predicate].
|
||||
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
|
||||
doc { "Returns the last ${f.element} matching the given [predicate]." }
|
||||
throws("NoSuchElementException", "if no such ${f.element} is found.")
|
||||
sample("${f.sampleClass}.last")
|
||||
returns("T")
|
||||
body {
|
||||
"""
|
||||
@@ -716,6 +726,7 @@ object Elements : TemplateGroupBase() {
|
||||
specialFor(ArraysOfUnsigned) { inlineOnly() }
|
||||
|
||||
doc { "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
|
||||
sample("${f.sampleClass}.last")
|
||||
returns("T?")
|
||||
body {
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user