summaryrefslogtreecommitdiff
path: root/sources/scala/Option.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2004-09-29 16:05:57 +0000
committermichelou <michelou@epfl.ch>2004-09-29 16:05:57 +0000
commitf9cda0d53a8f14cf2e28480563ace06fe2ed8c48 (patch)
tree8db3ce9fd4273260f87f69b378ab80db6738897f /sources/scala/Option.scala
parent52877fa8cb607d4b4f9825fca9f96dc0f4d1a35d (diff)
downloadscala-f9cda0d53a8f14cf2e28480563ace06fe2ed8c48.tar.gz
scala-f9cda0d53a8f14cf2e28480563ace06fe2ed8c48.tar.bz2
scala-f9cda0d53a8f14cf2e28480563ace06fe2ed8c48.zip
- added java.io.Serializable.
Diffstat (limited to 'sources/scala/Option.scala')
-rw-r--r--sources/scala/Option.scala77
1 files changed, 39 insertions, 38 deletions
diff --git a/sources/scala/Option.scala b/sources/scala/Option.scala
index bc997cc317..74611b804e 100644
--- a/sources/scala/Option.scala
+++ b/sources/scala/Option.scala
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2003, LAMP/EPFL **
+** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
@@ -18,50 +18,51 @@ package scala;
* @author Matthias Zenger
* @version 1.0, 16/07/2003
*/
-trait Option[+A] extends Iterable[A] {
+trait Option[+A] extends Iterable[A] with java.io.Serializable {
- def isEmpty: Boolean = this match {
- case None => true
- case _ => false
- }
+ def isEmpty: Boolean = this match {
+ case None => true
+ case _ => false
+ }
- def get: A = match {
- case None => error("None.get")
- case Some(x) => x
- }
+ def get: A = match {
+ case None => error("None.get")
+ case Some(x) => x
+ }
- def get[B >: A](default: B): B = match {
- case None => default
- case Some(x) => x
- }
+ def get[B >: A](default: B): B = match {
+ case None => default
+ case Some(x) => x
+ }
- def map[B](f: A => B): Option[B] = match {
- case None => None
- case Some(x) => Some(f(x))
- }
+ def map[B](f: A => B): Option[B] = match {
+ case None => None
+ case Some(x) => Some(f(x))
+ }
- def flatMap[B](f: A => Option[B]): Option[B] = match {
- case None => None
- case Some(x) => f(x)
- }
+ def flatMap[B](f: A => Option[B]): Option[B] = match {
+ case None => None
+ case Some(x) => f(x)
+ }
- def filter(p: A => Boolean): Option[A] = match {
- case None => None
- case Some(x) => if (p(x)) Some(x) else None
- }
+ def filter(p: A => Boolean): Option[A] = match {
+ case None => None
+ case Some(x) => if (p(x)) Some(x) else None
+ }
- override def foreach(f: A => Unit): Unit = match {
- case None => ()
- case Some(x) => f(x)
- }
+ override def foreach(f: A => Unit): Unit = match {
+ case None => ()
+ case Some(x) => f(x)
+ }
- def elements: Iterator[A] = match {
- case None => Iterator.empty
- case Some(x) => Iterator.fromValues(x)
- }
+ def elements: Iterator[A] = match {
+ case None => Iterator.empty
+ case Some(x) => Iterator.fromValues(x)
+ }
+
+ def toList: List[A] = match {
+ case None => List()
+ case Some(x) => List(x)
+ }
- def toList: List[A] = match {
- case None => List()
- case Some(x) => List(x)
- }
}