Map.filter() returns Map instead of List of Entries

This commit is contained in:
Ilya Ryzhenkov
2014-06-09 23:24:45 +04:00
parent 6849fb8358
commit 4167359c08
2 changed files with 23 additions and 3 deletions
@@ -205,7 +205,21 @@ fun filtering(): List<GenericFunction> {
return FilteringStream(this, true, predicate)
"""
}
include(Maps)
doc(Maps) { "Returns a map containing all key-value pairs matching the given *predicate*" }
returns(Maps) { "Map<K, V>" }
body(Maps) {
"""
val result = HashMap<K,V>()
for (entry in this) {
if (predicate(entry)) {
result.put(entry.key, entry.value)
}
}
return result
"""
}
}
templates add f("filterTo(destination: C, predicate: (T) -> Boolean)") {