tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,4 @@
case class Tree[+A](value: A, left: Option[Tree[A]], right: Option[Tree[A]]) {
def map[B](f: A => B): Tree[B] =
Tree(f(value), left map (_.map(f)), right map (_.map(f)))
}

View file

@ -0,0 +1,5 @@
class Employee(val name: String)
class Manager(name: String) extends Employee(name)
val t = Tree(new Manager("PHB"), None, None)
val t2: Tree[Employee] = t

View file

@ -0,0 +1,2 @@
def toName(e: Employee) = e.name
val treeOfNames = t.map(toName)

View file

@ -0,0 +1 @@
trait Function1[-T1, +R]

View file

@ -0,0 +1,6 @@
case class Tree[+A](value: A, left: Option[Tree[A]], right: Option[Tree[A]]) {
def map[B](f: A => B): Tree[B] =
Tree(f(value), left map (_.map(f)), right map (_.map(f)))
def find[B >: A](what: B): Boolean =
(value == what) || left.map(_.find(what)).getOrElse(false) || right.map(_.find(what)).getOrElse(false)
}

View file

@ -0,0 +1,2 @@
if (t2.find(new Employee("Dilbert")))
println("Call Catbert!")

View file

@ -0,0 +1,4 @@
trait DFA {
type Element
val map = new collection.mutable.HashMap[Element, DFA]()
}