@@ -30,27 +30,19 @@ import kotlin.reflect.KClass
3030 * @param R The target type to filter elements to.
3131 * @param C The type of the destination mutable collection.
3232 * @param destination The mutable collection to which the filtered elements will be added.
33- * @param iterator The iterator function that processes the filtered elements and their index.
3433 * @param predicate The predicate function that determines whether an element should be included based on its type and other criteria.
3534 */
3635inline fun <reified R , C : MutableCollection <in R >> Iterable <* >.filterPointer (
3736 destination : C ? ,
38- iterator : (R , Int ) -> Unit ,
3937 predicate : (R ) -> Boolean ,
40- ) {
41- var index = 0
42-
38+ ) =
4339 forEach { element ->
4440 val fulfilled = predicate(element as R )
4541
46- if (fulfilled && destination != null ) {
42+ if (fulfilled && destination != null )
4743 destination.add(element)
48- iterator(element, index)
49- }
5044
51- index++
5245 }
53- }
5446
5547/* *
5648 * Filters elements of the iterable by their runtime type and a predicate, and adds the matching elements to the specified mutable collection.
@@ -63,24 +55,19 @@ inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterPointer(
6355 * @param R The target type to filter elements to.
6456 * @param C The type of the destination mutable collection.
6557 * @param destination The mutable collection to which the filtered elements will be added.
66- * @param iterator The iterator function that processes the filtered elements and their index.
6758 * @param predicate The predicate function that determines whether an element should be included based on its type and other criteria.
6859 */
6960inline fun <R : Any , C : MutableCollection <in R >> Iterable <* >.filterPointer (
7061 kClass : KClass <out R >,
7162 destination : C ? ,
72- iterator : (R ) -> Unit ,
7363 predicate : (R ) -> Boolean ,
74- ) {
64+ ) =
7565 @Suppress(" UNCHECKED_CAST" )
7666 forEach { element ->
7767 // Cannot be replaced with reified type due to type erasure
7868 (element as ? R ) ? : return @forEach
7969 val fulfilled = kClass.isInstance(element) && predicate(element)
8070
81- if (fulfilled && destination != null ) {
71+ if (fulfilled && destination != null )
8272 destination.add(element)
83- iterator(element)
84- }
8573 }
86- }
0 commit comments