Created
December 16, 2015 09:54
-
-
Save nrinaudo/e795c8f0cf1c6a89419d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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