KT-20357: Add samples for filter functions
This commit is contained in:
committed by
Abduqodiri Qurbonzoda
parent
ca6e430e89
commit
1009a240f2
@@ -108,6 +108,8 @@ public actual inline fun CharArray.elementAt(index: Int): Char {
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements that are instances of specified class.
|
||||
*
|
||||
* @sample samples.collections.Collections.Filtering.filterIsInstanceJVM
|
||||
*/
|
||||
public fun <R> Array<*>.filterIsInstance(klass: Class<R>): List<R> {
|
||||
return filterIsInstanceTo(ArrayList<R>(), klass)
|
||||
@@ -115,6 +117,8 @@ public fun <R> Array<*>.filterIsInstance(klass: Class<R>): List<R> {
|
||||
|
||||
/**
|
||||
* Appends all elements that are instances of specified class to the given [destination].
|
||||
*
|
||||
* @sample samples.collections.Collections.Filtering.filterIsInstanceToJVM
|
||||
*/
|
||||
public fun <C : MutableCollection<in R>, R> Array<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
@@ -18,6 +18,8 @@ import kotlin.ranges.reversed
|
||||
|
||||
/**
|
||||
* Returns a list containing all elements that are instances of specified class.
|
||||
*
|
||||
* @sample samples.collections.Collections.Filtering.filterIsInstanceJVM
|
||||
*/
|
||||
public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
|
||||
return filterIsInstanceTo(ArrayList<R>(), klass)
|
||||
@@ -25,6 +27,8 @@ public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
|
||||
|
||||
/**
|
||||
* Appends all elements that are instances of specified class to the given [destination].
|
||||
*
|
||||
* @sample samples.collections.Collections.Filtering.filterIsInstanceToJVM
|
||||
*/
|
||||
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
@@ -18,6 +18,8 @@ package kotlin.sequences
|
||||
* Returns a sequence containing all elements that are instances of specified class.
|
||||
*
|
||||
* The operation is _intermediate_ and _stateless_.
|
||||
*
|
||||
* @sample samples.collections.Collections.Filtering.filterIsInstanceJVM
|
||||
*/
|
||||
public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -28,6 +30,8 @@ public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
|
||||
* Appends all elements that are instances of specified class to the given [destination].
|
||||
*
|
||||
* The operation is _terminal_.
|
||||
*
|
||||
* @sample samples.collections.Collections.Filtering.filterIsInstanceToJVM
|
||||
*/
|
||||
public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
Reference in New Issue
Block a user