Skip to content

Instantly share code, notes, and snippets.

@FlorianX
Created October 11, 2011 18:14
Show Gist options
  • Save FlorianX/1278895 to your computer and use it in GitHub Desktop.
Save FlorianX/1278895 to your computer and use it in GitHub Desktop.
Übung 1
object Phonebook {
var entries = List[Entry]()
def += (e: Entry) = {
entries ++= List(e)
entries = entries.toSet.toList
this
}
/*
//merge this into one def below
def ++=(l:List[Entry]) = {
entries ++= l
entries = entries.toSet.toList
this
}
def ++=(s:Set[Entry]) = {
entries ++= s
entries = entries.toSet.toList
this
}
*/
def ++=(c:Collection[Entry]) = {
entries ++= c.toList
entries = entries.toSet.toList
this
}
override def toString(): String = {
entries.sortWith((e1,e2) => e1.lastname < e2.lastname).mkString(sep = "\n")
}
}
@obcode
Copy link

obcode commented Oct 11, 2011

object Phonebook {
var entries = ListEntry
def +=(e:Entry){ // hier fehlt mir der Rueckgabewert oder?
entries ++= List(e)
this
}
def ++=(l:List[Entry]){
entries ++= l
this
}

override def toString(): String = {
entries.sortWith((e1,e2) => e1.lastName < e2.lastName).mkString(sep = "\n")
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment