Breaking change. Map operations revisited.

This commit is contained in:
Ilya Ryzhenkov
2014-06-09 23:27:42 +04:00
parent 4167359c08
commit ce5f7e9d61
6 changed files with 140 additions and 108 deletions
@@ -431,19 +431,6 @@ public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean): List<T> {
return filterTo(ArrayList<T>(), predicate)
}
/**
* Returns a map containing all key-value pairs matching the given *predicate*
*/
public inline fun <K, V> Map<K, V>.filter(predicate: (Map.Entry<K, V>) -> Boolean): Map<K, V> {
val result = HashMap<K,V>()
for (entry in this) {
if (predicate(entry)) {
result.put(entry.key, entry.value)
}
}
return result
}
/**
* Returns a stream containing all elements matching the given *predicate*
*/
@@ -528,13 +515,6 @@ public inline fun <T> Iterable<T>.filterNot(predicate: (T) -> Boolean): List<T>
return filterNotTo(ArrayList<T>(), predicate)
}
/**
* Returns a list containing all elements not matching the given *predicate*
*/
public inline fun <K, V> Map<K, V>.filterNot(predicate: (Map.Entry<K, V>) -> Boolean): List<Map.Entry<K, V>> {
return filterNotTo(ArrayList<Map.Entry<K, V>>(), predicate)
}
/**
* Returns a stream containing all elements not matching the given *predicate*
*/
@@ -674,14 +654,6 @@ public inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterNotTo(desti
return destination
}
/**
* Appends all elements not matching the given *predicate* to the given *destination*
*/
public inline fun <K, V, C : MutableCollection<in Map.Entry<K, V>>> Map<K, V>.filterNotTo(destination: C, predicate: (Map.Entry<K, V>) -> Boolean): C {
for (element in this) if (!predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements not matching the given *predicate* to the given *destination*
*/
@@ -778,14 +750,6 @@ public inline fun <T, C : MutableCollection<in T>> Iterable<T>.filterTo(destinat
return destination
}
/**
* Appends all elements matching the given *predicate* into the given *destination*
*/
public inline fun <K, V, C : MutableCollection<in Map.Entry<K, V>>> Map<K, V>.filterTo(destination: C, predicate: (Map.Entry<K, V>) -> Boolean): C {
for (element in this) if (predicate(element)) destination.add(element)
return destination
}
/**
* Appends all elements matching the given *predicate* into the given *destination*
*/