holgerbrandl
09/24/2018, 9:19 AMdiesieben07
09/24/2018, 12:06 PMholgerbrandl
09/24/2018, 12:08 PMdiesieben07
09/24/2018, 12:14 PMholgerbrandl
09/24/2018, 12:15 PMdiesieben07
09/24/2018, 12:16 PMholgerbrandl
09/24/2018, 12:18 PM{ heightCm }
. Currently the user has to specify them again.diesieben07
09/24/2018, 12:20 PMggplot(x = Person::heightCm)
diesieben07
09/24/2018, 12:20 PMholgerbrandl
09/24/2018, 12:29 PMholgerbrandl
09/24/2018, 12:35 PMx = ::conservation
? The type context is known because of refied generics.holgerbrandl
09/24/2018, 12:36 PMholgerbrandl
09/24/2018, 12:40 PMimport krangl.SleepPattern
import krangl.sleepPatterns
import kravis.GGPlot
import kravis.ggplot
import kotlin.reflect.KProperty1
inline fun <reified T> Iterable<T>.buildPlot(
x: KProperty1<T, *>,
y: KProperty1<T, *>
): GGPlot {
val map = map { x.get(it) to y.get(it) }
// later convert data to actual plot
return ggplot()
}
val basePlot = sleepPatterns.buildPlot(
x = SleepPattern::conservation,
y = SleepPattern::bodywt
)
// nicer but not legit:
val basePlot = sleepPatterns.buildPlot(
x = ::conservation,
y = ::bodywt
)
diesieben07
09/24/2018, 12:42 PMfun <T : Any> buildPlot(referenceExtractor: (T).() -> KProperty0<*>) = TODO()
Called like this:
buildPlot<MyClass> { ::propertyOfMyClass }
But that then requires an instance of MyClass
inside buildPlot
to call the lambda. And it is really just starting to bend the language in ways it's not designed to goholgerbrandl
09/24/2018, 12:50 PMIterable<T>
I have tons of instances of T. It’s a great solution which I would have never found myself, thanks a lot. 🙂holgerbrandl
09/24/2018, 12:50 PMdiesieben07
09/24/2018, 1:01 PMdiesieben07
09/24/2018, 1:01 PMholgerbrandl
09/24/2018, 1:02 PM