summaryrefslogtreecommitdiff
path: root/docs/examples/xml/phonebook/phonebook3.scala
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2007-03-23 16:17:43 +0000
committerIulian Dragos <jaguarul@gmail.com>2007-03-23 16:17:43 +0000
commite06381565db6615dfc0d384b76fd332ff93c6299 (patch)
treef6f9a6721e27bf30de40d5256150f5ccbd3a9b03 /docs/examples/xml/phonebook/phonebook3.scala
parentb809bf2730a76316082b1e5ba8e6dcef48e7bbc3 (diff)
downloadscala-e06381565db6615dfc0d384b76fd332ff93c6299.tar.gz
scala-e06381565db6615dfc0d384b76fd332ff93c6299.tar.bz2
scala-e06381565db6615dfc0d384b76fd332ff93c6299.zip
Fixed compilation errors in distribution examples.
Diffstat (limited to 'docs/examples/xml/phonebook/phonebook3.scala')
-rw-r--r--docs/examples/xml/phonebook/phonebook3.scala21
1 files changed, 10 insertions, 11 deletions
diff --git a/docs/examples/xml/phonebook/phonebook3.scala b/docs/examples/xml/phonebook/phonebook3.scala
index ec49d450f4..cd02490696 100644
--- a/docs/examples/xml/phonebook/phonebook3.scala
+++ b/docs/examples/xml/phonebook/phonebook3.scala
@@ -14,8 +14,8 @@ object phonebook3 {
/** returns true if this element's first child is the right 'name'
* x is treated a if it was a singleton sequence here.
*/
- def hasName ( x: Seq[Node] ) = x(0).child.elements.next match {
- case <name>{ Text(Name) }</name> => true
+ def hasName ( x: Seq[Node] ) = x(0).child.elements.exists {
+ case <name>{Text(Name)}</name> => true
case _ => false
}
@@ -41,12 +41,12 @@ object phonebook3 {
/** walks through tree, returns changed/copied updated tree */
def copyOrChange ( ch: Iterator[Node] ):List[Node] = {
- for( val c <- ch ) yield c match {
+ for( val c <- ch ) yield c match {
- case x @ <entry>{ ch1 @ _* }</entry> if hasName( x ) =>
+ case x @ <entry>{ ch1 @ _* }</entry> if hasName(x) =>
val it = ch1.elements;
val nameElem:Seq[Node] = it.next; // grab 'name' element
- val ch2 = nameElem concat copyOrChange( it ); // concat with updated seq
+ val ch2 = nameElem ++ copyOrChange( it ); // concat with updated seq
if( ch1 == ch2 ) // not present: add as first entry
@@ -63,13 +63,12 @@ object phonebook3 {
</entry>
case y @ <phone>{ _* }</phone> if hasWhere( y ) =>
- Console.println("c = "+c);
- <phone where={ Where }>{ newPhone }</phone>
+ Console.println("phone: "+c);
+ <phone where={ Where }>{ newPhone }</phone>
- case _ =>
- Console.println("c = "+c);
- Console.println("c.attributes= "+c.attributes);
- c
+ case _ =>
+ Console.println("default "+c);
+ c
}
}.toList ; // for ... yield ... returns Iterator, convert to list