Rearrange platform specialized functions

Place them according to their operation to ArrayOps and Filtering.
This commit is contained in:
Ilya Gorbunov
2017-11-14 08:01:33 +03:00
parent eda8bbacb3
commit 32b68ae1d5
9 changed files with 2700 additions and 2724 deletions
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -644,6 +644,13 @@ public inline fun <reified R> Iterable<*>.filterIsInstance(): List<@kotlin.inter
return filterIsInstanceTo(ArrayList<R>())
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass)
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*/
@@ -652,6 +659,15 @@ public inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterIsI
return destination
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
/**
* Returns a list containing all elements not matching the given [predicate].
*/
@@ -2353,19 +2369,3 @@ public fun Iterable<Double>.sum(): Double {
return sum
}
/**
* Returns a list containing all elements that are instances of specified class.
*/
public fun <R> Iterable<*>.filterIsInstance(klass: Class<R>): List<R> {
return filterIsInstanceTo(ArrayList<R>(), klass)
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
public fun <C : MutableCollection<in R>, R> Iterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
+21 -17
View File
@@ -397,6 +397,16 @@ public inline fun <reified R> Sequence<*>.filterIsInstance(): Sequence<@kotlin.i
return filter { it is R } as Sequence<R>
}
/**
* Returns a sequence containing all elements that are instances of specified class.
*
* The operation is _intermediate_ and _stateless_.
*/
public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
@Suppress("UNCHECKED_CAST")
return filter { klass.isInstance(it) } as Sequence<R>
}
/**
* Appends all elements that are instances of specified type parameter R to the given [destination].
*
@@ -407,6 +417,17 @@ public inline fun <reified R, C : MutableCollection<in R>> Sequence<*>.filterIsI
return destination
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*
* The operation is _terminal_.
*/
public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}
/**
* Returns a sequence containing all elements not matching the given [predicate].
*
@@ -1851,20 +1872,3 @@ public fun Sequence<Double>.sum(): Double {
return sum
}
/**
* Returns a sequence containing all elements that are instances of specified class.
*/
public fun <R> Sequence<*>.filterIsInstance(klass: Class<R>): Sequence<R> {
@Suppress("UNCHECKED_CAST")
return filter { klass.isInstance(it) } as Sequence<R>
}
/**
* Appends all elements that are instances of specified class to the given [destination].
*/
public fun <C : MutableCollection<in R>, R> Sequence<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C {
@Suppress("UNCHECKED_CAST")
for (element in this) if (klass.isInstance(element)) destination.add(element as R)
return destination
}