Skip to content

Commit dac8c17

Browse files
committed
erasing type of transform functions
1 parent 5e014f4 commit dac8c17

File tree

32 files changed

+127
-125
lines changed

32 files changed

+127
-125
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public interface DataColumn<out T> : BaseColumn<T> {
109109

110110
override fun resolveSingleAfter(
111111
context: ColumnResolutionContext,
112-
conversion: (List<ColumnWithPath<T>>) -> List<ColumnWithPath<@UnsafeVariance T>>,
112+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
113113
): ColumnWithPath<T>? = this
114-
.transform(conversion)
114+
.transform(transform)
115115
.let { it as DataColumn<T> }
116116
.addPath()
117117

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl.kt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,27 +3949,60 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
39493949

39503950
@Deprecated(
39513951
message = "allDfs is deprecated, use recursively instead.",
3952-
replaceWith = ReplaceWith("this.allRecursively(includeGroups)"),
3952+
replaceWith = ReplaceWith("this.all().recursively(includeGroups)"),
39533953
level = DeprecationLevel.WARNING,
39543954
)
39553955
public fun ColumnSet<*>.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> =
39563956
if (includeGroups) dfs { true } else dfs { !it.isColumnGroup() }
39573957

39583958
@Deprecated(
39593959
message = "allDfs is deprecated, use recursively instead.",
3960-
replaceWith = ReplaceWith("this.allRecursively(includeGroups)"),
3960+
replaceWith = ReplaceWith("this.all().recursively(includeGroups)"),
39613961
level = DeprecationLevel.WARNING,
39623962
)
39633963
public fun String.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> = toColumnAccessor().allDfs(includeGroups)
39643964

39653965
@Deprecated(
39663966
message = "allDfs is deprecated, use recursively instead.",
3967-
replaceWith = ReplaceWith("this.allRecursively(includeGroups)"),
3967+
replaceWith = ReplaceWith("this.all().recursively(includeGroups)"),
39683968
level = DeprecationLevel.WARNING,
39693969
)
39703970
public fun KProperty<*>.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> =
39713971
toColumnAccessor().allDfs(includeGroups)
39723972

3973+
public fun <C> ColumnSet<C>.recursively(includeGroups: Boolean = true): ColumnSet<C> = object : ColumnSet<C> {
3974+
3975+
private fun flatten(list: List<ColumnWithPath<*>>): List<ColumnWithPath<*>> =
3976+
list
3977+
.filter { it.isColumnGroup() } // TODO should I include this from dfs?
3978+
.flatMap {
3979+
it.children()
3980+
.dfs()
3981+
.filter { includeGroups || !it.isColumnGroup() }
3982+
}
3983+
3984+
override fun resolve(
3985+
context: ColumnResolutionContext,
3986+
): List<ColumnWithPath<C>> = this@recursively
3987+
.resolveAfterTransform(context = context, transform = ::flatten)
3988+
3989+
override fun resolveAfterTransform(
3990+
context: ColumnResolutionContext,
3991+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
3992+
): List<ColumnWithPath<C>> = this@recursively
3993+
.transform { transform(it) as List<ColumnWithPath<C>> }
3994+
.resolveAfterTransform(context = context, transform = ::flatten)
3995+
}
3996+
3997+
public fun <C> ColumnSet<C>.rec(includeGroups: Boolean = true): ColumnSet<C> = recursively(includeGroups)
3998+
3999+
public fun <C> ColumnSet<C>.allRecursively(includeGroups: Boolean = true): ColumnSet<C> =
4000+
wrap().recursively(includeGroups = includeGroups)
4001+
4002+
public fun <C> ColumnSet<C>.allRec(includeGroups: Boolean = true): ColumnSet<C> =
4003+
allRecursively(includeGroups = includeGroups)
4004+
4005+
39734006
// endregion
39744007

39754008
// region allAfter

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/join.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class ColumnMatch<C>(public val left: ColumnReference<C>, public val righ
111111

112112
override fun resolveAfterTransform(
113113
context: ColumnResolutionContext,
114-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<C>>,
114+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
115115
): List<ColumnWithPath<C>> {
116116
throw UnsupportedOperationException()
117117
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnReference.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public interface ColumnReference<out C> : SingleColumn<C> {
3939

4040
override fun resolveSingleAfter(
4141
context: ColumnResolutionContext,
42-
conversion: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<@UnsafeVariance C>>,
42+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
4343
): ColumnWithPath<C>? =
4444
context.df
4545
.asColumnGroup()
46-
.transform { conversion(it as List<ColumnWithPath<C>>) }
46+
.transform { transform(it as List<ColumnWithPath<C>>) }
4747
.resolve(context)
4848
.toDataFrame()
4949
.getColumn<C>(path(), context.unresolvedColumnsPolicy)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnSet.kt

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ package org.jetbrains.kotlinx.dataframe.columns
33
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
44
import org.jetbrains.kotlinx.dataframe.DataColumn
55
import org.jetbrains.kotlinx.dataframe.DataFrame
6-
import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
7-
import org.jetbrains.kotlinx.dataframe.api.toColumnGroup
8-
import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
9-
import org.jetbrains.kotlinx.dataframe.impl.columns.transform
10-
import org.jetbrains.kotlinx.dataframe.impl.columns.tree.dfs
11-
import org.jetbrains.kotlinx.dataframe.impl.columns.wrap
12-
import org.jetbrains.kotlinx.dataframe.impl.emptyPath
6+
import org.jetbrains.kotlinx.dataframe.impl.columns.*
137

148
/**
159
* Entity that can be resolved into a list of [columns][DataColumn].
@@ -18,11 +12,21 @@ import org.jetbrains.kotlinx.dataframe.impl.emptyPath
1812
* @param C common type of resolved columns
1913
*/
2014
public interface ColumnSet<out C> {
15+
16+
/**
17+
* Resolves this [ColumnSet] as a [List]<[ColumnWithPath]<[C]>>.
18+
* In many cases this function [transforms][ColumnSet.transform] a parent [ColumnSet] to reach
19+
* the current [ColumnSet] result.
20+
*/
2121
public fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<C>>
2222

23+
/**
24+
* Resolves this [ColumnSet] as a [List]<[ColumnWithPath]<[C]>> after applying [transform] to the parent
25+
* [ColumnSet]. This essentially injects a call right before the current in the [ColumnSet.resolve] chain.
26+
*/
2327
public fun resolveAfterTransform(
2428
context: ColumnResolutionContext,
25-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<@UnsafeVariance C>>,
29+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
2630
): List<ColumnWithPath<C>>
2731
}
2832

@@ -35,35 +39,3 @@ public class ColumnResolutionContext internal constructor(
3539
}
3640

3741
internal enum class UnresolvedColumnsPolicy { Fail, Skip, Create }
38-
39-
public fun <C> ColumnSet<C>.recursively(includeGroups: Boolean = true): ColumnSet<C> = object : ColumnSet<C> {
40-
41-
private fun flatten(list: List<ColumnWithPath<C>>): List<ColumnWithPath<C>> =
42-
list
43-
.filter { it.isColumnGroup() } // TODO should I include this from dfs?
44-
.flatMap {
45-
it.children()
46-
.dfs()
47-
.filter { includeGroups || !it.isColumnGroup() } as List<ColumnWithPath<C>>
48-
}
49-
50-
override fun resolve(
51-
context: ColumnResolutionContext,
52-
): List<ColumnWithPath<C>> = this@recursively
53-
.resolveAfterTransform(context = context, transform = ::flatten)
54-
55-
override fun resolveAfterTransform(
56-
context: ColumnResolutionContext,
57-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<C>>,
58-
): List<ColumnWithPath<C>> = this@recursively
59-
.transform(transform)
60-
.resolveAfterTransform(context = context, transform = ::flatten)
61-
}
62-
63-
public fun <C> ColumnSet<C>.rec(includeGroups: Boolean = true): ColumnSet<C> = recursively(includeGroups)
64-
65-
public fun <C> ColumnSet<C>.allRecursively(includeGroups: Boolean = true): ColumnSet<C> =
66-
wrap().recursively(includeGroups = includeGroups)
67-
68-
public fun <C> ColumnSet<C>.allRec(includeGroups: Boolean = true): ColumnSet<C> =
69-
allRecursively(includeGroups = includeGroups)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/SingleColumn.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public interface SingleColumn<out C> : ColumnSet<C> {
1515

1616
override fun resolveAfterTransform(
1717
context: ColumnResolutionContext,
18-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<@UnsafeVariance C>>,
18+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
1919
): List<ColumnWithPath<C>> = resolveSingleAfter(context, transform)?.let { listOf(it) } ?: emptyList()
2020

2121
public fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<C>?
2222

2323
public fun resolveSingleAfter(
2424
context: ColumnResolutionContext,
25-
conversion: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<@UnsafeVariance C>>,
25+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
2626
): ColumnWithPath<C>?
2727
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/DataFrameReceiver.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnGroupWithPathImpl
88
import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
99
import org.jetbrains.kotlinx.dataframe.impl.columns.missing.MissingColumnGroup
1010
import org.jetbrains.kotlinx.dataframe.impl.columns.missing.MissingDataColumn
11-
import org.jetbrains.kotlinx.dataframe.impl.columns.transform
1211

1312
private fun <T> DataFrame<T>.unbox(): DataFrame<T> = when (this) {
1413
is ColumnGroupWithParent -> source.unbox()
@@ -57,15 +56,15 @@ internal open class DataFrameReceiver<T>(
5756

5857
override fun resolveSingleAfter(
5958
context: ColumnResolutionContext,
60-
conversion: (List<ColumnWithPath<DataRow<T>>>) -> List<ColumnWithPath<DataRow<T>>>,
59+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
6160
): ColumnWithPath<DataRow<T>>? =
6261
DataColumn.createColumnGroup(
6362
name = "",
6463
df = df
6564
.columns()
6665
.map { it.addPath(emptyPath()) }
6766
.let { it as List<ColumnWithPath<DataRow<T>>> }
68-
.let(conversion)
67+
.let(transform)
6968
.toDataFrame {
7069

7170
} as DataFrame<T>,

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/ConfiguredAggregateColumn.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ internal class ConfiguredAggregateColumn<C> private constructor(
3131

3232
override fun resolveAfterTransform(
3333
context: ColumnResolutionContext,
34-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<C>>,
34+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
3535
): List<ColumnWithPath<C>> =
36-
resolve(context, columns.transform(transform))
36+
resolve(context, columns.transform(transform) as ColumnSet<C>)
3737

3838
companion object {
3939

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/pivot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal class PivotChainColumnSet<C>(val first: ColumnSet<C>, val second: Colum
5353

5454
override fun resolveAfterTransform(
5555
context: ColumnResolutionContext,
56-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<C>>,
56+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
5757
): List<ColumnWithPath<C>> {
5858
throw UnsupportedOperationException("Not implemented")
5959
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/sort.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ internal class ColumnsWithSortFlag<C>(val column: ColumnSet<C>, val flag: SortFl
112112

113113
override fun resolveAfterTransform(
114114
context: ColumnResolutionContext,
115-
transform: (List<ColumnWithPath<C>>) -> List<ColumnWithPath<C>>,
115+
transform: (List<ColumnWithPath<*>>) -> List<ColumnWithPath<*>>,
116116
): List<ColumnWithPath<C>> = column
117-
.transform(transform)
117+
.transform { transform(it) as List<ColumnWithPath<C>> }
118118
.resolve(context)
119119
.map { it.addFlag(flag) }
120120
}

0 commit comments

Comments
 (0)