Marc Knaup
02/24/2020, 12:14 PMUser::
over and over again? 🤔Gabriel Shanahan
02/24/2020, 12:20 PMMarc Knaup
02/24/2020, 12:32 PMKProperty
and I don’t have an instance of User
here. Thus I cannot call anything where User
is a receiver parameter.Gabriel Shanahan
02/24/2020, 12:34 PMGabriel Shanahan
02/24/2020, 12:35 PMMarc Knaup
02/24/2020, 12:36 PMinline fun <reified Value : Any> conversion(noinline configure: Conversion<Value>.() -> Unit) =
conversion(valueClass = Value::class, configure = configure)
Gabriel Shanahan
02/24/2020, 12:42 PMclass Test(val a: Int, b: Int)
fun myFun(test: Test, f:Test.() -> Unit) {
test.f()
}
myFun(Test(1, 2)) {
println((::a).javaClass)
}
Gabriel Shanahan
02/24/2020, 12:42 PMGabriel Shanahan
02/24/2020, 12:42 PMMarc Knaup
02/24/2020, 12:42 PMGabriel Shanahan
02/24/2020, 12:44 PMMarc Knaup
02/24/2020, 12:44 PMrobstoll
02/24/2020, 12:44 PMclass A {
val a = 1
fun foo() = "a"
}
fun bar(f: A.() -> Unit) = 1
fun test() {
bar { ::a }
}
Marc Knaup
02/24/2020, 12:45 PMA
.robstoll
02/24/2020, 12:47 PMMarc Knaup
02/24/2020, 12:51 PMMarc Knaup
02/24/2020, 12:51 PMfield(typeOf(???)::someProp)
Marc Knaup
02/24/2020, 12:51 PMrobstoll
02/24/2020, 12:52 PMMarc Knaup
02/24/2020, 12:53 PMwithType<User> {
field(::birthday)
}
I guess that would change the language a lot 😅earroyoron
02/24/2020, 12:56 PMMarc Knaup
02/24/2020, 12:56 PMapply()
on a class, only on an instance.Marc Knaup
02/24/2020, 12:57 PMUser.apply { … }
won’t work (or use the companion, which is not intended)robstoll
02/24/2020, 12:58 PMtypeOf
give some kind of meta-structure for the corresponding type (just saw that typeOf now actually exists in Kotlin -> KType). However, it is dumb and you cannot do something like:
fun bar(f: KType<A>.() -> Unit) = 1
@ExperimentalStdlibApi
fun test() {
bar { ::a }(typeOf(A))
}
Marc Knaup
02/24/2020, 1:02 PMrobstoll
02/24/2020, 1:04 PMwith(typeOf(A)){
::a
}
which is what you wanted no?Marc Knaup
02/24/2020, 1:05 PMMarc Knaup
02/24/2020, 1:06 PMKType
isn’t generic though :)Marc Knaup
02/24/2020, 1:06 PM::a
potentially ambiguous now.
Is it a property of KType
or of the type that KType
is referring to? ^^robstoll
02/24/2020, 1:09 PMtypeOf(A).a
which returns KProperty<Int>
robstoll
02/24/2020, 1:09 PMMarc Knaup
02/24/2020, 1:10 PMTormentedDan
02/24/2020, 11:52 PMTormentedDan
02/24/2020, 11:52 PMTormentedDan
02/24/2020, 11:54 PM