Rob Elliot
11/15/2022, 1:09 PMRob Elliot
11/15/2022, 1:11 PMuser.links.self
and it compile for this class:
data class User(val id: Id) {
val links = object {
val self = "/v1/users/$id"
}
}
Rob Elliot
11/15/2022, 1:13 PMdata class User(val id: Id) {
val links = Links(
self = "/v1/users/$id"
)
data class Links(
val self: String
)
}
which works fine but feels & reads slightly more laborious.hfhbd
11/15/2022, 1:15 PMdata class User(val id: Long) {
val links = Links()
inner class Links {
val self = "/v1/users/$id"
}
}
Or an interfaceRob Elliot
11/15/2022, 1:17 PMEmil Kantis
11/15/2022, 3:06 PMdata class User(val id: Id): Linkable<Links.Self> by selfLink("/v1/users/$id")
interface Linkable<T : Links> {
val links: T
}
sealed interface Links {
data class Self(val self: String) : Links
}
fun selfLink(path: String) = object : Linkable<Links.Self> { override val links = Links.Self(path) }
elizarov
11/15/2022, 3:06 PMelizarov
11/15/2022, 3:08 PMelizarov
11/15/2022, 3:08 PMelizarov
11/15/2022, 3:10 PMRob Elliot
11/15/2022, 3:10 PMRob Elliot
11/15/2022, 3:11 PMefemoney
11/15/2022, 3:24 PMelizarov
11/15/2022, 3:42 PMelizarov
11/15/2022, 3:44 PMgildor
11/17/2022, 3:35 AMobject Dependencies {
val ktor = object {
val core = …
val auth = …
}
}
to allow use it like Dependencies.ktor.auth
It’s probably has the same issues as internal in terms of that it requires some object name generation. I would be probably would be fine if it would be required to use named object like:
val ktor = object Ktor {}
So no class name generation requiedelizarov
11/17/2022, 8:10 AMinner object
for such a use-cases.gildor
11/17/2022, 8:31 AM