Erix
Erix

Reputation: 7105

what does def * (def asterisk) mean?

an example in some code I'm looking at

class X {
    def k1 = column[Int]("k1")
    def k2 = column[Int]("k2")
    def * = (k1, k2)
}

Is it just a normal function name or is there something special about it?

Upvotes: 3

Views: 228

Answers (2)

Feyyaz
Feyyaz

Reputation: 3216

It's the name of an abstract method in Slick's Table, used to tell Slick how it should convert those columns into a Scala object, and the Scala object back into the database columns. The complete code in your question would be

class X(tag: Tag) extends Table[(Int, Int)] {
    def k1 = column[Int]("k1")
    def k2 = column[Int]("k2")
    override def * : ProvenShape[(Int, Int)] = (k1, k2) // you may prefer to omit 'override' and return type for readability
}

So, if you extend Table, you have to override this method.

You can find more complex usages in the documentation.

Upvotes: 1

Tim
Tim

Reputation: 27421

It is just a normal function name. Scala allows pretty much any sequence of characters to be a function name, though some need to be quoted using backticks.

def `def` = "def"

Upvotes: 0

Related Questions