diff options
author | Martin Odersky <odersky@gmail.com> | 2009-02-23 19:21:05 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-02-23 19:21:05 +0000 |
commit | bf35b888e49afb245883571cc00cbb5ec7341f24 (patch) | |
tree | 8c060484dde8c122f1d65fceedf0dd962a4ad90c /src/library | |
parent | a4baf48a5fb38f29d462accc57f93032955efa0e (diff) | |
download | scala-bf35b888e49afb245883571cc00cbb5ec7341f24.tar.gz scala-bf35b888e49afb245883571cc00cbb5ec7341f24.tar.bz2 scala-bf35b888e49afb245883571cc00cbb5ec7341f24.zip |
fixed several problems with cyclic references u...
fixed several problems with cyclic references uncovered by experimenting
with collections. Added early type definitions.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Tuple2.scala.notyet | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/library/scala/Tuple2.scala.notyet b/src/library/scala/Tuple2.scala.notyet new file mode 100644 index 0000000000..bed6bd3a9a --- /dev/null +++ b/src/library/scala/Tuple2.scala.notyet @@ -0,0 +1,83 @@ + +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Tuple2.scala 14794 2008-04-23 08:15:17Z washburn $ + +// generated by genprod on Wed Apr 23 10:06:16 CEST 2008 (with extra methods) + +package scala + +object Tuple2 { + class IterableOps[CC[+B] <: Iterable[B], A1, A2](tuple: (CC[A1], Iterable[A2])) { + def zip: CC[(A1, A2)] = { + val elems1 = tuple._1.elements + val elems2 = tuple._2.elements + val b = tuple._1.newBuilder[B] + while (elems1.hasNext && elems2.hasNext) + b += ((elems1.next, elems2.next)) + b.result + } + def map[B](f: (A1, A2) => B): CC[B] = { + val elems1 = tuple._1.elements + val elems2 = tuple._2.elements + val b = tuple._1.newBuilder[B] + while (elems1.hasNext && elems2.hasNext) + b += f(elems1.next, elems2.next) + b.result + } + def flatMap[B](f: (A1, A2) => CC[B]) CC[B] = { + val elems1 = tuple._1.elements + val elems2 = tuple._2.elements + val b = tuple._1.newBuilder[B] + while (elems1.hasNext && elems2.hasNext) + b ++= f(elems1.next, elems2.next) + b.result + } + def foreach(f: (A1, A2) => Unit) { + val elems1 = tuple._1.elements + val elems2 = tuple._2.elements + while (elems1.hasNext && elems2.hasNext) + f(elems1.next, elems2.next) + } + def forall(p: (A1, A2) => Boolean): Boolean = { + val elems1 = tuple._1.elements + val elems2 = tuple._2.elements + while (elems1.hasNext && elems2.hasNext) + if (!p(elems1.next, elems2.next)) return false + true + } + def exists(p: (A1, A2) => Boolean): Boolean = { + val elems1 = tuple._1.elements + val elems2 = tuple._2.elements + while (elems1.hasNext && elems2.hasNext) + if (p(elems1.next, elems2.next)) return true + false + } + } + + implicit def tupleOfIterableWrapper[CC[+B] <: Iterable[B], A1, A2](tuple: (CC[A1], Iterable[A2])) = + new IterableOps(tuple) +} + +/** Tuple2 is the canonical representation of a @see Product2 + * + */ +case class Tuple2[+T1, +T2](_1:T1, _2:T2) + extends Product2[T1, T2] { + + override def toString() = { + val sb = new StringBuilder + sb.append('(').append(_1).append(',').append(_2).append(')') + sb.toString + } + + /** Swap the elements of the tuple */ + def swap: Tuple2[T2,T1] = Tuple2(_2, _1) + +} |