Changeset 6678 for lang/scala
- Timestamp:
- 02/14/08 20:22:11 (10 months ago)
- Location:
- lang/scala/sandbox
- Files:
-
- 1 added
- 2 modified
-
lib/scala-sandbox.jar (added)
-
src/jp/ne/cappuccino/keisuken/scl/lang/Loop.scala (modified) (6 diffs)
-
webpages/lib/scala-sandbox.jar (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
lang/scala/sandbox/src/jp/ne/cappuccino/keisuken/scl/lang/Loop.scala
r6677 r6678 9 9 } 10 10 11 def f ind[A, B]11 def foreach[A, B] 12 12 (iterable: Iterable[A])(f: (A, Break[B]) => Unit): Option[B] = { 13 13 val break = new Break[B]() … … 24 24 } 25 25 26 def find [A](cond: => Boolean)(f: Break[A] => Unit): Option[A] = {26 def findWhile[A](cond: => Boolean)(f: Break[A] => Unit): Option[A] = { 27 27 val break = new Break[A]() 28 28 while(break.cond && cond) f(break) 29 break.value 30 } 31 32 def findDoWhile[A](cond: => Boolean)(f: Break[A] => Unit): Option[A] = { 33 val break = new Break[A]() 34 do {f(break)} while(break.cond && cond) 29 35 break.value 30 36 } … … 33 39 34 40 var i = 0 35 find [Int](true) {break =>41 findWhile[Int](true) {break => 36 42 if(i >= 5) 37 43 break(i) … … 43 49 } 44 50 45 val result = find[String, String]( 51 i = 0 52 findWhile[Int](i < 10) {break => 53 if(i == 20) 54 break(i) 55 else 56 i += 1 57 } match { 58 case Some(result) => println(result) 59 case None => println("Not found") 60 } 61 62 i = 0 63 findDoWhile[Int]({i += 1; i < 10}) {break => 64 if(i == 5) break(i) 65 } match { 66 case Some(result) => println(result) 67 case None => println("Not found") 68 } 69 70 val result = foreach[String, String]( 46 71 Array("aaa", "bbb", "ccc")) {(value, break) => 47 72 if(value.equals("ddd")) … … 50 75 println(result) 51 76 52 f ind[String,String](Array("aaa", "bbb", "ccc")) {(value, break) =>77 foreach[String,String](Array("aaa", "bbb", "ccc")) {(value, break) => 53 78 if(value.equals("bbb")) 54 79 break(value) … … 58 83 } 59 84 60 f ind[Int,Int](1 to 10) {(i, break) =>85 foreach[Int,Int](1 to 10) {(i, break) => 61 86 if(i % 2 == 1) break(i) 62 87 } match {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)