Permalink
Browse files

Added orElse to Type.

Tree and Symbol each have the analogous method, so consistency
calls along with utility for putting it on Type.
  • Loading branch information...
1 parent 5ec9dbd commit fe8280c020eab60a7f94cb1faa50ba412635caea @paulp paulp committed Apr 23, 2013
Showing with 8 additions and 0 deletions.
  1. +6 −0 src/reflect/scala/reflect/api/Types.scala
  2. +2 −0 src/reflect/scala/reflect/internal/Types.scala
@@ -209,6 +209,12 @@ trait Types {
/******************* helpers *******************/
+ /** Provides an alternate if type is NoType.
+ *
+ * @group Helpers
+ */
+ def orElse(alt: => Type): Type
+
/** Substitute symbols in `to` for corresponding occurrences of references to
* symbols `from` in this type.
*/
@@ -742,6 +742,8 @@ trait Types
def map[T](f: Type => T): List[T] = collect(Type.this) map f
}
+ @inline final def orElse(alt: => Type): Type = if (this ne NoType) this else alt
+
/** Returns optionally first type (in a preorder traversal) which satisfies predicate `p`,
* or None if none exists.
*/

0 comments on commit fe8280c

Please sign in to comment.