Skip to content

Instantly share code, notes, and snippets.

@x3ro
Created June 23, 2011 21:58
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 x3ro/1043741 to your computer and use it in GitHub Desktop.
Save x3ro/1043741 to your computer and use it in GitHub Desktop.
import scala.collection.mutable._
class Foo {
}
object Foo {
trait Transform[-A >: B, B, +R[_] <: Set[_]] {
def apply(a: A) : R[B]
}
class Person(val name: String)
case class Student(override val name: String, val matrNum: Int) extends Person(name) {
def rev = Student(name, matrNum.toString().reverse.toInt)
}
class PersToStud extends Transform[Person,Student,HashSet] {
def apply(a:Person):HashSet[Student] = a match {
case x:Student => HashSet(x.rev)
case _ => HashSet()
}
}
def main(args:Array[String]) {
var pts: Transform[Student,Student,Set] = new PersToStud
println(pts(new Student("julia",1234)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment