summaryrefslogtreecommitdiff
path: root/src/library/scala/Product.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-23 08:32:53 +0000
committerPaul Phillips <paulp@improving.org>2010-02-23 08:32:53 +0000
commit84ecd8c45a66c2e27eb4b0782f0d1b3c4c55466d (patch)
treedfac5858c64f30b40668d5b26e2e8e931e897fc5 /src/library/scala/Product.scala
parent68cbfeac525cad416a3e2fd4b90d13631dd81bc6 (diff)
downloadscala-84ecd8c45a66c2e27eb4b0782f0d1b3c4c55466d.tar.gz
scala-84ecd8c45a66c2e27eb4b0782f0d1b3c4c55466d.tar.bz2
scala-84ecd8c45a66c2e27eb4b0782f0d1b3c4c55466d.zip
Added productElementName to Product.
case class field names your heart desires. Review by odersky. scala> case class Foo[T](kilroy: String, burma: List[T], shave: Seq[Int]) defined class Foo scala> Foo("was here", List('myanmar), Seq(25, 25)) res0: Foo[Symbol] = Foo(was here,List('myanmar),List(25, 25)) scala> 0 to 2 map (res0 productElementName _) res1: IndexedSeq[String] = IndexedSeq(kilroy, burma, shave)
Diffstat (limited to 'src/library/scala/Product.scala')
-rw-r--r--src/library/scala/Product.scala14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/library/scala/Product.scala b/src/library/scala/Product.scala
index 8521cf2437..417b87f191 100644
--- a/src/library/scala/Product.scala
+++ b/src/library/scala/Product.scala
@@ -20,7 +20,7 @@ package scala
*/
trait Product extends Equals {
- /** for a product <code>A(x_1,...,x_k)</code>, returns <code>x_(n+1)</code>
+ /** For a product <code>A(x_1,...,x_k)</code>, returns <code>x_(n+1)</code>
* for <code>0 &lt;= n &lt; k</code>
*
* @param n the index of the element to return
@@ -29,6 +29,18 @@ trait Product extends Equals {
*/
def productElement(n: Int): Any
+ /** Returns the name of the field at the given index from the definition
+ * of the class.
+ *
+ * @param n the index of the element name to return
+ * @throws NoSuchElementException if the name data is unavailable for any reason
+ * @throws IndexOutOfBoundsException if the index is out of range
+ * @return a String representing the field name
+ */
+ def productElementName(n: Int): String =
+ // the method implementation is synthetic - if it is not generated we always throw.
+ throw new NoSuchElementException()
+
/** return k for a product <code>A(x_1,...,x_k)</code>
*/
def productArity: Int