tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -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)))
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
def toName(e: Employee) = e.name
|
||||
val treeOfNames = t.map(toName)
|
||||
|
|
@ -0,0 +1 @@
|
|||
trait Function1[-T1, +R]
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
if (t2.find(new Employee("Dilbert")))
|
||||
println("Call Catbert!")
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
trait DFA {
|
||||
type Element
|
||||
val map = new collection.mutable.HashMap[Element, DFA]()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue