Changeset 6756 for lang/scala/sandbox

Show
Ignore:
Timestamp:
02/16/08 03:33:05 (10 months ago)
Author:
keisuken
Message:

write to new loop algorithm at last comment.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/scala/sandbox/src/jp/ne/cappuccino/keisuken/scl/lang/Loop.scala

    r6746 r6756  
    269269  } 
    270270} 
     271/* 
     272  val context = new DynamicVariable[Found[Any]](null) 
     273 
     274  def found[T](result :T) { 
     275    context.value.result = Some(result) 
     276    context.value.cond = false 
     277  } 
     278 
     279  def notFound[T](result :T) { 
     280    context.value.result = None 
     281    context.value.cond = false 
     282  } 
     283 
     284  def findFor2[A, B] 
     285    (iterable: Iterable[A])(p: A => Unit): Option[B] = { 
     286    context.withValue(new Found[Any]) { 
     287      val iterator = iterable.elements 
     288      while(context.value.cond && iterator.hasNext) p(iterator.next) 
     289      context.value.result.asInstanceOf[Option[B]] 
     290    } 
     291  } 
     292 
     293 
     294 
     295    println("---- findFor2(iterator)") 
     296    sResult = findFor2[String,String](Array("abc", "cde", "efg")){value => 
     297      if(value == "efg") found(value) 
     298    } 
     299    sResult match { 
     300      case Some(result) => println(result) 
     301      case None => println("Not found") 
     302    } 
     303 
     304 
     305 
     306    println("---- findFor2(iterator)") 
     307    sResult = findFor2(Array("abc", "cde", "efg")){value :String => 
     308      if(value == "efg") found(value) 
     309    } 
     310    sResult match { 
     311      case Some(result) => println(result) 
     312      case None => println("Not found") 
     313    } 
     314*/