Skip to content

Instantly share code, notes, and snippets.

@nrinaudo
Created December 16, 2015 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrinaudo/e795c8f0cf1c6a89419d to your computer and use it in GitHub Desktop.
Save nrinaudo/e795c8f0cf1c6a89419d to your computer and use it in GitHub Desktop.
// Represents a named collection of documents of type A
trait Documents[A] {
def name: String
def take(target: Int): Documents[A]
// [...]
}
// Represents a collection of named collections of documents.
// A is the type of a document, D that of a named collection of documents
case class Data[A, D[_] <: Documents[_]](docs: List[D[A]]) {
// Makes sure no D contains more than target documents
def cap(target: Int): Data[A, Documents] = {
// Fails to compile: the map returns a D[_]
//copy(cats = cats.map(_.take(target)))
// Compiles
Data(docs.map(_.asInstanceOf[Documents[A]].take(target)))
}
// [...]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment