nkiesel
06/17/2022, 7:33 PMEntry has a toPair() method, why does Pair does not have a toEntry() method?Paul Griffith
06/17/2022, 7:40 PMDominaezzz
06/17/2022, 7:46 PMEntry for?ephemient
06/17/2022, 7:54 PMAbstractMap.SimpleEntry - but from the Kotlin's perspective, you have to choose between Map.Entry and MutableMap.MutableEntry. also in line with Dominic's point, there are Kotlin APIs that accept Pair, but what do you want an Entry for?nkiesel
06/17/2022, 7:58 PMephemient
06/17/2022, 7:59 PMkotlin.Pair is not mutablenkiesel
06/17/2022, 8:00 PMephemient
06/17/2022, 8:09 PMfun <K, V> Pair<K, V>.toEntry() = object : Map.Entry<K, V> {
override val key: K = first
override val value: V = second
}
I don't think these would get much use in stdlib given that all other APIs (such as Iterable<Pair<K, V>>.toMap()) are based around PairDominaezzz
06/17/2022, 8:10 PMephemient
06/17/2022, 8:13 PMMap.Entry is an interface so a @JvmInline value class MyEntry<out K, out V>(pair: Pair<K, V>) : Map.Entry<K, V> would get immediately boxed, yes. and it would have to hold on to the original Pair since value classes don't support multiple values yet, and it would be impossible to implement MutableEntry this waynkiesel
06/17/2022, 8:13 PMDominaezzz
06/17/2022, 8:17 PMEntry exposes a key and a value but Pair doesn't have such semantics so there's no "correct" way to create an Entry from a Pair. The other direction is possible as a lossy conversion though.nkiesel
06/17/2022, 8:20 PMDominaezzz
06/17/2022, 8:20 PMDominaezzz
06/17/2022, 8:21 PMDominaezzz
06/17/2022, 8:21 PMRepresents a key/value pair held by a Map.Key first and value second.