`"" + columnRef` becomes `String`
Sample code (version 0.12.0):
val df1 = dataFrameOf("name", "age")(
"Alice", 15,
"Bob", 20,
"Charlie", 100
)
val name by column<String>()
val name_age by column<String>()
df1.add(name_age) { name + "!!!" }.also { println(it) }
df1.add(name_age) { "!!!" + name }.also { println(it) }
The first println (name + "!!!") produces:
name age name_age
0 Alice 15 Alice!!!
1 Bob 20 Bob!!!
2 Charlie 100 Charlie!!!
The second println ( "!!!" + name) produces:
name age name_age
0 Alice 15 !!!org.jetbrains.kotlinx.dataframe.im...
1 Bob 20 !!!org.jetbrains.kotlinx.dataframe.im...
2 Charlie 100 !!!org.jetbrains.kotlinx.dataframe.im...
The root cause is that In the two example + resolves to different functions. A foot gun that should be fixed.
It should indeed be fixed but unfortunately we can't. It's a language limitation.
Have you tried making a function like operator fun String.plus(something)?
Since
String already has a function plus, an extension function overload will never be called by default.
I would consider deprecating, and ultimately removing:
public operator fun ColumnReference<String>.plus.
Might indeed be a good idea to add ColumReference<String>.append() and .prepend() or something similar and through deprecations steer users to those :)
We still cannot prevent "" + anything from becoming a String though