Edward Muller
12/09/2023, 12:29 AMtypealias RequestGroupingKey = Triple<String, String, String>
Which one of this is more lighter weight & more performant?
val RequestGroupingKey.thing: String
get() = this.first
or
fun RequestGroupingKey.thing(): String = this.first
or is there something else I should be doing like a data class?Daniel Pitts
12/09/2023, 1:06 AMDaniel Pitts
12/09/2023, 1:10 AMdata class RequestGroupingKey(val thing: String, val ama: String, val bob:String)
gives you a better semantic type.
One of the downsides to what you wrote is that RequestGroupingKey
is simply an alias for Triple<String, String, String>
, which means anyone with any Triple<String, String, String>
can call .thing
on it. Which I'm assuming was not the intent.Edward Muller
12/09/2023, 1:10 AMDaniel Pitts
12/09/2023, 1:10 AMEdward Muller
12/09/2023, 1:11 AMDaniel Pitts
12/09/2023, 1:11 AMtypealias
is for callback signatures:
typealias SomeEventListener = (SomeEvent)->Unit
Daniel Pitts
12/09/2023, 1:12 AMArjan van Wieringen
12/10/2023, 7:53 PMDaniel Pitts
12/10/2023, 7:57 PMDaniel Pitts
12/10/2023, 7:58 PMArjan van Wieringen
12/11/2023, 6:54 AMCLOVIS
12/11/2023, 9:24 AMI mean the performance implications.Which implications are you thinking of? Typealiases are purely syntactic sugar, they do nothing, so they do not have any performance difference compared to using what they refer to directly.
Arjan van Wieringen
12/11/2023, 9:40 AM