Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created August 21, 2011 00:59
Show Gist options
  • Save jbrechtel/1159921 to your computer and use it in GitHub Desktop.
Save jbrechtel/1159921 to your computer and use it in GitHub Desktop.
Traits in Scala
trait Searchable {
def search(query: SearchQuery): Seq[SearchResults]
}
trait PaginationWithNominalType {
this: Searchable =>
def page(query: SearchQuery, pageSize: Int, pageNum: Int) = {
search(query).grouped(pageSize).toList(pageNum)
}
}
trait PaginationWithStructuralType {
this: { def search(query: SearchQuery): Seq[SearchResults] }
def page(query: SearchQuery, pageSize: Int, pageNum: Int) = {
search(query).grouped(pageSize).toList(pageNum)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment