7

I mean something like this:

fun operator Table.get(column_name: String) = this.column(column_name)
// Currently gives an error: "Expecting a top level declaration"

Table instance currently works like: table.column("column_name")

I want to make it work like this: table["column_name"]

Veneet Reddy
  • 2,707
  • 1
  • 24
  • 40

1 Answers1

9

This is possible, it's just that the operator keyword has go before the fun keyword in the declaration (as do other modifiers, such as infix, inline, etc.):

operator fun Table.get(column_name: String) = this.column(column_name)
zsmb13
  • 85,752
  • 11
  • 221
  • 226