更新时间:2023-11-27 09:37:40
You can use filterKeys
:
val ab = abc.filterKeys { it in keys }
由于它是Kotlin,您甚至可以定义自己的扩展功能完全达到您的想象:
And since it is Kotlin, you could even define your own extension function to achieve exactly what you imagined:
fun <T> Map<T, *>.slice(keys: Iterable<T>) = filterKeys { it in keys }
val ab = abc.slice(keys)