Kotlin / dataframe

Structured data processing in Kotlin
https://kotlin.github.io/dataframe/overview.html
Apache License 2.0
839 stars 63 forks source link

[Future] context receiver support #325

Open Jolanrensen opened 1 year ago

Jolanrensen commented 1 year ago

Context receivers are a proposed Kotlin feature: https://github.com/Kotlin/KEEP/issues/259.

DataFrame could greatly benefit if this feature ever gets added properly since it's built around so many DSLs. Oftentimes we are limited because we cannot write inline extension functions inside interfaces, requiring either to foil the public function space or to rewrite the function to not be inline (which is not always possible).

Example:

context(ColumnsSelectionDsl)
public inline fun <reified C> KProperty<*>.colsOf(): ColumnSet<Any?> =
    colsOf(typeOf<C>())

would enable you to write:

df.select { MyType::myGroup.colsOf<Int>() }

instead of

df.select { (MyType::myGroup)().colsOf<Int>() }

And this is only the tip of the iceberg of course!

zaleslaw commented 1 year ago

Wire this to the MAIN ticket to let the Kotlin Designers that we are waiting for them to improve our library! (I am serious)

Jolanrensen commented 1 year ago

They, unfortunately, won't work on it until after K2 is stabilized.

koperagen commented 9 months ago

imagine you want to save "group" in aggregate as a column. For example, you want to calculate aggregation and observe data too

groupBy.aggregate {
this into "group"
sum() into "sum"
}

Now "this" is a complex type AggregatableDsl or something like this, and it won't be recognized as DataFrame. While it can be fixed in multiple ways, i like that with context parameters type will become context(AggregateDsl) DataFrame.(DataFrame) -> Unit and this will become a DataFrame without additional work