From 11ebee09918841b5b4175b60399af4e04fade833 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 14 May 2011 16:54:59 +0000 Subject: Added flatten to Option so Some(Some(x)).flatte... Added flatten to Option so Some(Some(x)).flatten returns Option[Int] and not Iterable[Int]. No review. --- src/compiler/scala/tools/nsc/backend/opt/Inliners.scala | 2 +- src/library/scala/Option.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index 4ac4864d43..debd33a986 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -644,7 +644,7 @@ abstract class Inliners extends SubComponent { def lookupIMethod(meth: Symbol, receiver: Symbol): Option[IMethod] = { def tryParent(sym: Symbol) = icodes icode sym flatMap (_ lookupMethod meth) - receiver.info.baseClasses.iterator map tryParent find (_.isDefined) getOrElse None + receiver.info.baseClasses.iterator map tryParent find (_.isDefined) flatten } } /* class Inliner */ } /* class Inliners */ diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala index bab3a1c759..dfd647d649 100644 --- a/src/library/scala/Option.scala +++ b/src/library/scala/Option.scala @@ -146,6 +146,9 @@ sealed abstract class Option[+A] extends Product with Serializable { def flatMap[B](f: A => Option[B]): Option[B] = if (isEmpty) None else f(this.get) + def flatten[B](implicit ev: A <:< Option[B]): Option[B] = + if (isEmpty) None else ev(this.get) + /** Returns this $option if it is nonempty '''and''' applying the predicate $p to * this $option's value returns true. Otherwise, return $none. * -- cgit v1.2.3