Colton Idle
05/24/2023, 12:34 PMmapOf
size 1. Is there any way to enforce that?
Basically my method is
fun myFunction(event: Map)
but technically right now it can be mis-used because you can add more than 1 item in the map. Ideas?ephemient
05/24/2023, 12:35 PMColton Idle
05/24/2023, 12:38 PMephemient
05/24/2023, 12:39 PMColton Idle
05/24/2023, 12:41 PMfirst
and second
propertyColton Idle
05/24/2023, 12:42 PMephemient
05/24/2023, 12:46 PMColton Idle
05/24/2023, 12:53 PMlazynoda
05/24/2023, 1:09 PMPair<A, B>
and internally transform into a Map<A, B>
with mapOf(pair)
?
fun myFunction(event: Pair<String, Any>) {
val mapEvent = mapOf(event)
// Go to Moshi...
}
Colton Idle
05/24/2023, 1:52 PMYoussef Shoaib [MOD]
05/24/2023, 2:46 PMRob Elliot
05/24/2023, 3:05 PMfun myFunction(pair: Pair<String, Any>)
to fun myFunction(key: String, value: Any)
.
It lets you give the two values sensible parameter names in the function, reduces the amount of generics in the type signatures, and even if the caller has a Pair it's trivial to decompose it.