Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created October 12, 2020 12:36
Show Gist options
  • Save ch8n/e0d67da8e884aafd783bbb5b1e548f0b to your computer and use it in GitHub Desktop.
Save ch8n/e0d67da8e884aafd783bbb5b1e548f0b to your computer and use it in GitHub Desktop.
map resolved by linked hashmap
fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V>
= if (pairs.size > 0){
pairs.toMap(LinkedHashMap(mapCapacity(pairs.size)))
}else{
emptyMap()
}
// Linked HashMap signature
class LinkedHashMap<K, V> : MutableMap<K, V>
// since MutableMap<K, V> has Map as parent class
// Casting it to map make it immutable* (read-only)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment