aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
blob: 0da6d7a58f8cebbb61aa5b0a97b68465969cb219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package ca.allanwang.kau.kotlin

/**
 * Created by Allan Wang on 2017-08-05.
 */

/**
 * Replica of [java.util.Vector.removeIf] in Java
 * Since we don't have access to the internals of our extended class,
 * We will simply iterate and remove when the filter returns {@code false}
 */
@Synchronized
inline fun <T, C : MutableIterable<T>> C.kauRemoveIf(filter: (item: T) -> Boolean): C {
    val iter = iterator()
    while (iter.hasNext())
        if (filter(iter.next())) iter.remove()
    return this
}