Add toList() operation on Maps
This commit is contained in:
committed by
Andrey Breslav
parent
5537ff5f3c
commit
118126c744
@@ -397,6 +397,16 @@ public fun String.toLinkedList(): LinkedList<Char> {
|
||||
return toCollection(LinkedList<Char>())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all key-value pairs
|
||||
*/
|
||||
public fun <K, V> Map<K, V>.toList(): List<Map.Entry<K, V>> {
|
||||
val result = ArrayList<Map.Entry<K, V>>(size)
|
||||
for (item in this)
|
||||
result.add(item)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all elements
|
||||
*/
|
||||
|
||||
@@ -59,6 +59,20 @@ fun snapshots(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("toList()") {
|
||||
only(Maps)
|
||||
doc { "Returns a List containing all key-value pairs" }
|
||||
returns("List<Map.Entry<K, V>>")
|
||||
body {
|
||||
"""
|
||||
val result = ArrayList<Map.Entry<K, V>>(size)
|
||||
for (item in this)
|
||||
result.add(item)
|
||||
return result
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("toList()") {
|
||||
doc { "Returns a List containing all elements" }
|
||||
returns("List<T>")
|
||||
|
||||
Reference in New Issue
Block a user