-
-
Save leedm777/2028836 to your computer and use it in GitHub Desktop.
Traits in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
trait PaginationWithAbstractMethod { | |
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