Skip to content

Commit

Permalink
Merge branch 'master' into continued-columnsselectiondsl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Jan 30, 2024
2 parents 9450590 + d3b278f commit 31c71c3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import org.jetbrains.kotlinx.dataframe.columns.values

// region DataColumn

public fun <T> DataColumn<T>.forEach(action: (T) -> Unit): Unit = values.forEach(action)
public inline fun <T> DataColumn<T>.forEach(action: (T) -> Unit): Unit = values().forEach(action)

public fun <T> DataColumn<T>.forEachIndexed(action: (Int, T) -> Unit): Unit = values.forEachIndexed(action)
public inline fun <T> DataColumn<T>.forEachIndexed(action: (Int, T) -> Unit): Unit = values().forEachIndexed(action)

// endregion

// region DataFrame

public fun <T> DataFrame<T>.forEach(action: RowExpression<T, Unit>): Unit = rows().forEach { action(it, it) }
public inline fun <T> DataFrame<T>.forEach(action: RowExpression<T, Unit>): Unit = rows().forEach { action(it, it) }

// endregion

// region GroupBy

public fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit): Unit = keys.forEach { key ->
public inline fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit): Unit = keys.forEach { key ->
val group = groups[key.index()]
body(GroupBy.Entry(key, group))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import org.jetbrains.kotlinx.dataframe.columns.values

// region DataColumn

public fun <T> DataColumn<T>.forEach(action: (T) -> Unit): Unit = values.forEach(action)
public inline fun <T> DataColumn<T>.forEach(action: (T) -> Unit): Unit = values().forEach(action)

public fun <T> DataColumn<T>.forEachIndexed(action: (Int, T) -> Unit): Unit = values.forEachIndexed(action)
public inline fun <T> DataColumn<T>.forEachIndexed(action: (Int, T) -> Unit): Unit = values().forEachIndexed(action)

// endregion

// region DataFrame

public fun <T> DataFrame<T>.forEach(action: RowExpression<T, Unit>): Unit = rows().forEach { action(it, it) }
public inline fun <T> DataFrame<T>.forEach(action: RowExpression<T, Unit>): Unit = rows().forEach { action(it, it) }

// endregion

// region GroupBy

public fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit): Unit = keys.forEach { key ->
public inline fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit): Unit = keys.forEach { key ->
val group = groups[key.index()]
body(GroupBy.Entry(key, group))
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
ksp = "1.9.0-1.0.12"
ksp = "1.9.21-1.0.15"
kotlinJupyter = "0.11.0-358"
ktlint = "3.4.5"
kotlin = "1.9.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@ package org.jetbrains.dataframe.gradle
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.findByType
import java.util.*

@Suppress("unused")
class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.plugins.apply(KspPluginApplier::class.java)
val name = "kotlin.dataframe.add.ksp"
val property = target.findProperty(name)?.toString()
var addKsp = true

if (property != null) {
if (property.equals("true", ignoreCase = true) || property.equals("false", ignoreCase = true)) {
addKsp = property.toBoolean()
} else {
target.logger.warn("Invalid value '$property' for '$name' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.")
}
}
if (addKsp) {
target.plugins.apply(KspPluginApplier::class.java)
}
target.afterEvaluate {
target.extensions.findByType<KspExtension>()?.arg("dataframe.resolutionDir", target.projectDir.absolutePath)
}
target.plugins.apply(SchemaGeneratorPlugin::class.java)
}
}
Expand All @@ -31,6 +47,5 @@ internal class KspPluginApplier : Plugin<Project> {
target.configurations.getByName("ksp").dependencies.add(
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
)
target.extensions.getByType<KspExtension>().arg("dataframe.resolutionDir", target.projectDir.absolutePath)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.jetbrains.dataframe.gradle

import java.util.Locale

fun String.toCamelCaseByDelimiters(delimiters: Regex): String {
return split(delimiters).joinToCamelCaseString().decapitalize()
return split(delimiters).joinToCamelCaseString().replaceFirstChar { it.lowercase(Locale.getDefault()) }
}

fun List<String>.joinToCamelCaseString(): String {
return joinToString(separator = "") { it.capitalize() }
return joinToString(separator = "") { s -> s.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class DataSchemaGenerator(
private val codeGenerator: com.google.devtools.ksp.processing.CodeGenerator,
) {

fun resolveImportStatements() = listOf(
::resolvePathImports,
).flatMap { it(resolver) }
fun resolveImportStatements(): List<ImportDataSchemaStatement> = resolvePathImports(resolver).toList()

class ImportDataSchemaStatement(
val origin: KSFile,
Expand Down

0 comments on commit 31c71c3

Please sign in to comment.