den bardadym den bardadym - 1 month ago 34
Scala Question

Scala with keyword usage

I found simple example:

class Post extends LongKeyedMapper[Post] with IdPK {
def getSingleton = Post

object title extends MappedText(this)
object text extends MappedText(this)
object date extends MappedDate(this)
}


object Post extends Post with LongKeyedMetaMapper[Post] {
def getPosts(startAt: Int, count: Int) = {
Post.findAll(OrderBy(Post.date, Descending), StartAt(startAt), MaxRows(count))
}

def getPostsCount = Post.count
}


What does it mean
with IdPK
?

Thanks.

Answer

with means that the class is using a Trait via mixin.

Post has the Trait IdPK (similar to a Java class can implements an Interface).

See also A Tour of Scala: Mixin Class Composition