summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-09-27 12:00:16 +0000
committermichelou <michelou@epfl.ch>2006-09-27 12:00:16 +0000
commit8d98363504373fbb30360cdf734e8f8f001b8def (patch)
treee0b4b718cc2e5acdce4b3568fc23faddec89bc74
parent9643a7ddc29a88ef0644a6543b1632255457d356 (diff)
downloadscala-8d98363504373fbb30360cdf734e8f8f001b8def.tar.gz
scala-8d98363504373fbb30360cdf734e8f8f001b8def.tar.bz2
scala-8d98363504373fbb30360cdf734e8f8f001b8def.zip
added code example to Scala comment in scala/Fu...
added code example to Scala comment in scala/Function<i>.scala
-rw-r--r--src/library/scala/Function0.scala16
-rw-r--r--src/library/scala/Function1.scala16
-rw-r--r--src/library/scala/Function2.scala16
3 files changed, 45 insertions, 3 deletions
diff --git a/src/library/scala/Function0.scala b/src/library/scala/Function0.scala
index 65e106caa4..2daf0de622 100644
--- a/src/library/scala/Function0.scala
+++ b/src/library/scala/Function0.scala
@@ -13,7 +13,21 @@ package scala
/**
- * Function with no parameters
+ * Function with no parameters. In the following example the definition of
+ * <code>currentSeconds</code> is a shorthand for the anonymous class
+ * definition <code>anonfun0</code>:
+ * <pre>
+ * <b>object</b> Main <b>extends</b> Application {
+ *
+ * <b>val</b> currentSeconds = () => System.currentTimeMillis() / 1000L
+ *
+ * <b>val</b> anonfun0 = <b>new</b> Function0[Long] {
+ * <b>def</b> apply(): Long = System.currentTimeMillis() / 1000L
+ * }
+ *
+ * Console.println(currentSeconds())
+ * Console.println(anonfun0())
+ * }</pre>
*/
trait Function0[+R] extends AnyRef {
def apply(): R
diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala
index aa6e114835..add41c8c58 100644
--- a/src/library/scala/Function1.scala
+++ b/src/library/scala/Function1.scala
@@ -13,7 +13,21 @@ package scala
/**
- * Function with 1 parameter
+ * Function with 1 parameter. In the following example the definition of
+ * <code>succ</code> is a shorthand for the anonymous class definition
+ * <code>anonfun1</code>:
+ * <pre>
+ * <b>object</b> Main <b>extends</b> Application {
+ *
+ * <b>val</b> succ = (x: Int) => x + 1
+ *
+ * <b>val</b> anonfun1 = <b>new</b> Function1[Int, Int] {
+ * <b>def</b> apply(x: Int): Int = x + 1
+ * }
+ *
+ * Console.println(succ(0))
+ * Console.println(anonfun1(0))
+ * }</pre>
*/
trait Function1[-T0, +R] extends AnyRef {
def apply(v0: T0): R
diff --git a/src/library/scala/Function2.scala b/src/library/scala/Function2.scala
index 422235f387..be23a05716 100644
--- a/src/library/scala/Function2.scala
+++ b/src/library/scala/Function2.scala
@@ -13,7 +13,21 @@ package scala
/**
- * Function with 2 parameters
+ * Function with 2 parameters. In the following example the definition of
+ * <code>max</code> is a shorthand for the anonymous class definition
+ * <code>anonfun2</code>:
+ * <pre>
+ * <b>object</b> Main <b>extends</b> Application {
+ *
+ * <b>val</b> max = (x: Int, y: Int) => <b>if</b> (x < y) y <b>else</b> x
+ *
+ * <b>val</b> anonfun2 = <b>new</b> Function2[Int, Int, Int] {
+ * <b>def</b> apply(x: Int, y: Int): Int = <b>if</b> (x < y) y <b>else</b> x
+ * }
+ *
+ * Console.println(max(0, 1))
+ * Console.println(anonfun2(0, 1))
+ * }</pre>
*/
trait Function2[-T0, -T1, +R] extends AnyRef {
def apply(v0: T0, v1: T1): R