mbonnin
02/21/2023, 2:54 PMMap
-like type I guess and property accesses would be cast to the build-time type (and assert if wrong). Does that make any sense?eygraber
02/21/2023, 3:02 PMmbonnin
02/21/2023, 3:06 PMmbonnin
02/21/2023, 3:06 PMmbonnin
02/21/2023, 3:08 PMeygraber
02/21/2023, 3:13 PMgenerates a lot of code that takes lots of time to compile
Wouldn't a build time type checker have the same issue? Or does the type checking take a negligible amount of time?
mbonnin
02/21/2023, 3:14 PMmbonnin
02/21/2023, 3:15 PMmbonnin
02/21/2023, 3:16 PMmbonnin
02/21/2023, 3:18 PMCasey Brooks
02/21/2023, 3:20 PMJsonElement
with #serialization (or other similar types from other serialization libs)mbonnin
02/21/2023, 3:21 PMMaybe generating value classes might help with the runtime issue?Maybe! Will check this!
send a POST request with the GraphQL query in the body, and the result will just be normal JSON that could be deserialized toThat works of course but the developer experience is nothing similar to having in-IDE autocomplete, inline documentation, deprecations, etc...JsonElement
Casey Brooks
02/21/2023, 3:23 PMmbonnin
02/21/2023, 3:24 PMmbonnin
02/21/2023, 3:25 PMephemient
02/21/2023, 3:47 PMvalue class Response(private val data: Map<String, Any>) {
val foo: Foo
get() = Foo(data["foo"] as Map<String, Any>)
val optional: String?
get() = data["optional"] as String?
}
etc.?ephemient
02/21/2023, 3:48 PMCasey Brooks
02/21/2023, 3:49 PMephemient
02/21/2023, 3:51 PMephemient
02/21/2023, 3:53 PMmbonnin
02/21/2023, 3:56 PMmbonnin
02/21/2023, 3:56 PMephemient
02/21/2023, 4:02 PMephemient
02/21/2023, 4:03 PMYoussef Shoaib [MOD]
02/24/2023, 5:05 AMobject MapDelegate {
operator fun <R> getValue(map: Map<String, Any>, prop: KProperty<*>): R = map[prop.name] as R
}
@JvmInline value class Response(private val data: Map<String, Any>): Map<String, Any> by data
val Response.foo: Foo? by MapDelegate
where MapDelegate can be used as a delegate for any object that is a Map<String, Any>
. Sadly value classes don't allow doing by underlyingValue
for some reason, and so I had to define them as extension properties. Only issue is that sadly the name of the property is accessed through the KProperty
object, which requires an object to exist per property.elizarov
02/24/2023, 9:44 AMtypealias PositiveInt = Int requires { it > 0 }
The additional requirement is completely erased at run-time but is checked at compile-time, so this code will not compile:
val x: Int = getSomeInt()
val y: PositiveInt = x // cannot assign PositiveInt to Int
But this code will compile:
val x: Int = getSomeInt()
require(x > 0)
val y: PositiveInt = x // OK
You can imagine using it with other types like Strings to represent domain-specific restricted string subsets, maps, etc.mbonnin
02/24/2023, 9:46 AMelizarov
02/24/2023, 10:30 AM