Skip to content
Newer
Older
100644 463 lines (403 sloc) 24.1 KB
8ac3654 Added more comments, removed StructuralEquality...
Matthias Zenger authored
1 /* __ *\
2 ** ________ ___ / / ___ Scala API **
807dbe5 @heathermiller Brings all copyrights (in comments) up-to-date, from 2011/12 to 2013
heathermiller authored
3 ** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
3d4d7ce added Array.deepToString, cleaned up MatchError
michelou authored
4 ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
8ac3654 Added more comments, removed StructuralEquality...
Matthias Zenger authored
5 ** /____/\___/_/ |_/____/_/ | | **
6 ** |/ **
7 \* */
8
29ac82f Removed Predef.Array*
michelou authored
9 package scala
23d2bfb @odersky Initial version.
odersky authored
10
e5c22d9 @paulp An overhaul of the collection-oriented methods ...
paulp authored
11 import scala.collection.{ mutable, immutable, generic }
12 import immutable.StringOps
13 import mutable.ArrayOps
14 import generic.CanBuildFrom
55b6094 @paulp Eliminate breaking relative names in source.
paulp authored
15 import scala.annotation.{ elidable, implicitNotFound }
16 import scala.annotation.elidable.ASSERTION
17 import scala.language.{implicitConversions, existentials}
e72f0c7 @odersky Massive redesign so that: scala> "hi" == "hi".r...
odersky authored
18
a0476af 2nd round of clean ups (see r25285)
michelou authored
19 /** The `Predef` object provides definitions that are accessible in all Scala
20 * compilation units without explicit qualification.
e4559e4 @heathermiller Improves documentation of scala.Predef.
heathermiller authored
21 *
22 * === Commonly Used Types ===
23 * Predef provides type aliases for types which are commonly used, such as
24 * the immutable collection types [[scala.collection.immutable.Map]],
25 * [[scala.collection.immutable.Set]], and the [[scala.collection.immutable.List]]
26 * constructors ([[scala.collection.immutable.::]] and
27 * [[scala.collection.immutable.Nil]]).
28 * The types `Pair` (a [[scala.Tuple2]]) and `Triple` (a [[scala.Tuple3]]), with
29 * simple constructors, are also provided.
30 *
31 * === Console I/O ===
32 * Predef provides a number of simple functions for console I/O, such as
33 * `print`, `println`, `readLine`, `readInt`, etc. These functions are all
34 * aliases of the functions provided by [[scala.Console]].
35 *
36 * === Assertions ===
37 *
38 * A set of `assert` functions are provided for use as a way to document
39 * and dynamically check invariants in code. `assert` statements can be elided
40 * at runtime by providing the command line argument `-Xdisable-assertions` to
41 * the `scala` command.
42 *
43 * Variants of `assert` intended for use with static analysis tools are also
44 * provided: `assume`, `require` and `ensuring`. `require` and `ensuring` are
45 * intended for use as a means of design-by-contract style specification
46 * of pre- and post-conditions on functions, with the intention that these
47 * specifications could be consumed by a static analysis tool. For instance,
48 *
49 * {{{
50 * def addNaturals(nats: List[Int]): Int = {
51 * require(nats forall (_ >= 0), "List contains negative numbers")
52 * nats.foldLeft(0)(_ + _)
53 * } ensuring(_ >= 0)
54 * }}}
55 *
56 * The declaration of `addNaturals` states that the list of integers passed should
57 * only contain natural numbers (i.e. non-negative), and that the result returned
58 * will also be natural. `require` is distinct from `assert` in that if the
59 * condition fails, then the caller of the function is to blame rather than a
60 * logical error having been made within `addNaturals` itself. `ensures` is a
61 * form of `assert` that declares the guarantee the function is providing with
62 * regards to it's return value.
63 *
64 * === Implicit Conversions ===
65 * A number of commonly applied implicit conversions are also defined here, and
66 * in the parent type [[scala.LowPriorityImplicits]]. Implicit conversions
67 * are provided for the "widening" of numeric values, for instance, converting a
68 * Short value to a Long value as required, and to add additional higher-order
69 * functions to Array values. These are described in more detail in the documentation of [[scala.Array]].
8ac3654 Added more comments, removed StructuralEquality...
Matthias Zenger authored
70 */
e72f0c7 @odersky Massive redesign so that: scala> "hi" == "hi".r...
odersky authored
71 object Predef extends LowPriorityImplicits {
e4559e4 @heathermiller Improves documentation of scala.Predef.
heathermiller authored
72 /**
73 * Retrieve the runtime representation of a class type. `classOf[T]` is equivalent to
74 * the class literal `T.class` in Java.
75 *
76 * @example {{{
77 * val listClass = classOf[List[_]]
78 * // listClass is java.lang.Class[List[_]] = class scala.collection.immutable.List
79 *
80 * val mapIntString = classOf[Map[Int,String]]
81 * // mapIntString is java.lang.Class[Map[Int,String]] = interface scala.collection.immutable.Map
82 * }}}
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
83 */
e4559e4 @heathermiller Improves documentation of scala.Predef.
heathermiller authored
84 def classOf[T]: Class[T] = null // This is a stub method. The actual implementation is filled in by the compiler.
12a9f76 @odersky added support of class literals
odersky authored
85
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
86 type String = java.lang.String
2ed9387 @odersky dual mode (generics or not) version of compiler...
odersky authored
87 type Class[T] = java.lang.Class[T]
12a9f76 @odersky added support of class literals
odersky authored
88
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
89 // miscelleaneous -----------------------------------------------------
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
90 scala.`package` // to force scala package object to be seen.
91 scala.collection.immutable.List // to force Nil, :: to be seen.
d4e3c78 namespaces
buraq authored
92
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
93 type Function[-A, +B] = Function1[A, B]
c72f7b2 @odersky *** empty log message ***
odersky authored
94
e5c22d9 @paulp An overhaul of the collection-oriented methods ...
paulp authored
95 type Map[A, +B] = immutable.Map[A, B]
96 type Set[A] = immutable.Set[A]
97 val Map = immutable.Map
98 val Set = immutable.Set
bb23d76 @paulp Specialization action.
paulp authored
99 // @deprecated("Use scala.AnyRef instead", "2.10.0")
100 // def AnyRef = scala.AnyRef
a961d3d @odersky 1.
odersky authored
101
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
102 // Manifest types, companions, and incantations for summoning
cba0cbb @xeno-by Improves backward compatibility of manifests
xeno-by authored
103 @annotation.implicitNotFound(msg = "No ClassManifest available for ${T}.")
104 @deprecated("Use scala.reflect.ClassTag instead", "2.10.0")
7aa4764 @odersky new starr with class manifests
odersky authored
105 type ClassManifest[T] = scala.reflect.ClassManifest[T]
1acb166 @xeno-by undeprecates manifests for 2.10.0
xeno-by authored
106 // TODO undeprecated until Scala reflection becomes non-experimental
107 // @deprecated("This notion doesn't have a corresponding concept in 2.10, because scala.reflect.runtime.universe.TypeTag can capture arbitrary types. Use type tags instead of manifests, and there will be no need in opt manifests.", "2.10.0")
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
108 type OptManifest[T] = scala.reflect.OptManifest[T]
cba0cbb @xeno-by Improves backward compatibility of manifests
xeno-by authored
109 @annotation.implicitNotFound(msg = "No Manifest available for ${T}.")
1acb166 @xeno-by undeprecates manifests for 2.10.0
xeno-by authored
110 // TODO undeprecated until Scala reflection becomes non-experimental
111 // @deprecated("Use scala.reflect.ClassTag (to capture erasures) or scala.reflect.runtime.universe.TypeTag (to capture types) or both instead", "2.10.0")
814cf34 @xeno-by Next generation of macros
xeno-by authored
112 type Manifest[T] = scala.reflect.Manifest[T]
cba0cbb @xeno-by Improves backward compatibility of manifests
xeno-by authored
113 @deprecated("Use scala.reflect.ClassTag instead", "2.10.0")
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
114 val ClassManifest = scala.reflect.ClassManifest
1acb166 @xeno-by undeprecates manifests for 2.10.0
xeno-by authored
115 // TODO undeprecated until Scala reflection becomes non-experimental
116 // @deprecated("Use scala.reflect.ClassTag (to capture erasures) or scala.reflect.runtime.universe.TypeTag (to capture types) or both instead", "2.10.0")
f54e5c8 @xeno-by resurrects manifests in their pre-2.10 glory
xeno-by authored
117 val Manifest = scala.reflect.Manifest
1acb166 @xeno-by undeprecates manifests for 2.10.0
xeno-by authored
118 // TODO undeprecated until Scala reflection becomes non-experimental
119 // @deprecated("This notion doesn't have a corresponding concept in 2.10, because scala.reflect.runtime.universe.TypeTag can capture arbitrary types. Use type tags instead of manifests, and there will be no need in opt manifests.", "2.10.0")
f54e5c8 @xeno-by resurrects manifests in their pre-2.10 glory
xeno-by authored
120 val NoManifest = scala.reflect.NoManifest
7aa4764 @odersky new starr with class manifests
odersky authored
121
1acb166 @xeno-by undeprecates manifests for 2.10.0
xeno-by authored
122 // TODO undeprecated until Scala reflection becomes non-experimental
123 // @deprecated("Use scala.reflect.classTag[T] and scala.reflect.runtime.universe.typeTag[T] instead", "2.10.0")
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
124 def manifest[T](implicit m: Manifest[T]) = m
3cebcd7 @xeno-by adds deprecation annotations on manifest incantations
xeno-by authored
125 @deprecated("Use scala.reflect.classTag[T] instead", "2.10.0")
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
126 def classManifest[T](implicit m: ClassManifest[T]) = m
1acb166 @xeno-by undeprecates manifests for 2.10.0
xeno-by authored
127 // TODO undeprecated until Scala reflection becomes non-experimental
128 // @deprecated("This notion doesn't have a corresponding concept in 2.10, because scala.reflect.runtime.universe.TypeTag can capture arbitrary types. Use type tags instead of manifests, and there will be no need in opt manifests.", "2.10.0")
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
129 def optManifest[T](implicit m: OptManifest[T]) = m
d5b02c8 @odersky new arrays are done.
odersky authored
130
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
131 // Minor variations on identity functions
132 def identity[A](x: A): A = x // @see `conforms` for the implicit version
d5b81b6 @adriaanm misc fixes while working on virtualizing patter...
adriaanm authored
133 @inline def implicitly[T](implicit e: T) = e // for summoning implicit values from the nether world -- TODO: when dependent method types are on by default, give this result type `e.type`, so that inliner has better chance of knowing which method to inline in calls like `implicitly[MatchingStrategy[Option]].zero`
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
134 @inline def locally[T](x: T): T = x // to communicate intent and avoid unmoored statements
7da30bf @odersky added `locally' to Predef.
odersky authored
135
f82acf5 @paulp Reducing the sbt launcher footprint by eliminat...
paulp authored
136 // Apparently needed for the xml library
137 val $scope = scala.xml.TopScope
138
8922c4e @paulp Moved ClassfileAnnotation/StaticAnnotation/Anno...
paulp authored
139 // Deprecated
98a0360 @odersky *** empty log message ***
odersky authored
140
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
141 @deprecated("Use `sys.error(message)` instead", "2.9.0")
5bada81 @paulp Imported sbt.Process into trunk, in the guise o...
paulp authored
142 def error(message: String): Nothing = sys.error(message)
98a0360 @odersky *** empty log message ***
odersky authored
143
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
144 @deprecated("Use `sys.exit()` instead", "2.9.0")
5bada81 @paulp Imported sbt.Process into trunk, in the guise o...
paulp authored
145 def exit(): Nothing = sys.exit()
14203ea - overloaded Predef.exit with exit(Int) that ta...
mihaylov authored
146
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
147 @deprecated("Use `sys.exit(status)` instead", "2.9.0")
5bada81 @paulp Imported sbt.Process into trunk, in the guise o...
paulp authored
148 def exit(status: Int): Nothing = sys.exit(status)
98a0360 @odersky *** empty log message ***
odersky authored
149
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
150 @deprecated("Use `formatString.format(args: _*)` or `arg.formatted(formatString)` instead", "2.9.0")
8922c4e @paulp Moved ClassfileAnnotation/StaticAnnotation/Anno...
paulp authored
151 def format(text: String, xs: Any*) = augmentString(text).format(xs: _*)
152
153 // errors and asserts -------------------------------------------------
154
a0476af 2nd round of clean ups (see r25285)
michelou authored
155 /** Tests an expression, throwing an `AssertionError` if false.
156 * Calls to this method will not be generated if `-Xelide-below`
157 * is at least `ASSERTION`.
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
158 *
159 * @see elidable
4af7703 @retronym Address doc comment rot in the standard library.
retronym authored
160 * @param assertion the expression to test
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
161 */
c71af41 @paulp Generalized -Xdisable-assertions into an annota...
paulp authored
162 @elidable(ASSERTION)
3d4d7ce added Array.deepToString, cleaned up MatchError
michelou authored
163 def assert(assertion: Boolean) {
98a0360 @odersky *** empty log message ***
odersky authored
164 if (!assertion)
257a184 Refactored portability support
mihaylov authored
165 throw new java.lang.AssertionError("assertion failed")
98a0360 @odersky *** empty log message ***
odersky authored
166 }
bd07456 Refactored class library.
Matthias Zenger authored
167
a0476af 2nd round of clean ups (see r25285)
michelou authored
168 /** Tests an expression, throwing an `AssertionError` if false.
169 * Calls to this method will not be generated if `-Xelide-below`
170 * is at least `ASSERTION`.
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
171 *
172 * @see elidable
4af7703 @retronym Address doc comment rot in the standard library.
retronym authored
173 * @param assertion the expression to test
174 * @param message a String to include in the failure message
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
175 */
b973195 @paulp Working on the inliner, discovered that a few k...
paulp authored
176 @elidable(ASSERTION) @inline
177 final def assert(assertion: Boolean, message: => Any) {
98a0360 @odersky *** empty log message ***
odersky authored
178 if (!assertion)
694b5ca @odersky added requires and ensuring methods.
odersky authored
179 throw new java.lang.AssertionError("assertion failed: "+ message)
98a0360 @odersky *** empty log message ***
odersky authored
180 }
181
a0476af 2nd round of clean ups (see r25285)
michelou authored
182 /** Tests an expression, throwing an `AssertionError` if false.
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
183 * This method differs from assert only in the intent expressed:
184 * assert contains a predicate which needs to be proven, while
185 * assume contains an axiom for a static checker. Calls to this method
a0476af 2nd round of clean ups (see r25285)
michelou authored
186 * will not be generated if `-Xelide-below` is at least `ASSERTION`.
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
187 *
188 * @see elidable
4af7703 @retronym Address doc comment rot in the standard library.
retronym authored
189 * @param assumption the expression to test
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
190 */
c71af41 @paulp Generalized -Xdisable-assertions into an annota...
paulp authored
191 @elidable(ASSERTION)
3d4d7ce added Array.deepToString, cleaned up MatchError
michelou authored
192 def assume(assumption: Boolean) {
b83bbad @odersky *** empty log message ***
odersky authored
193 if (!assumption)
694b5ca @odersky added requires and ensuring methods.
odersky authored
194 throw new java.lang.AssertionError("assumption failed")
b83bbad @odersky *** empty log message ***
odersky authored
195 }
196
a0476af 2nd round of clean ups (see r25285)
michelou authored
197 /** Tests an expression, throwing an `AssertionError` if false.
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
198 * This method differs from assert only in the intent expressed:
199 * assert contains a predicate which needs to be proven, while
200 * assume contains an axiom for a static checker. Calls to this method
a0476af 2nd round of clean ups (see r25285)
michelou authored
201 * will not be generated if `-Xelide-below` is at least `ASSERTION`.
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
202 *
203 * @see elidable
4af7703 @retronym Address doc comment rot in the standard library.
retronym authored
204 * @param assumption the expression to test
205 * @param message a String to include in the failure message
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
206 */
b973195 @paulp Working on the inliner, discovered that a few k...
paulp authored
207 @elidable(ASSERTION) @inline
208 final def assume(assumption: Boolean, message: => Any) {
b83bbad @odersky *** empty log message ***
odersky authored
209 if (!assumption)
bb04dae typo: s/assumptopm/assumption/
lorch authored
210 throw new java.lang.AssertionError("assumption failed: "+ message)
694b5ca @odersky added requires and ensuring methods.
odersky authored
211 }
212
a0476af 2nd round of clean ups (see r25285)
michelou authored
213 /** Tests an expression, throwing an `IllegalArgumentException` if false.
214 * This method is similar to `assert`, but blames the caller of the method
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
215 * for violating the condition.
216 *
4af7703 @retronym Address doc comment rot in the standard library.
retronym authored
217 * @param requirement the expression to test
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
218 */
694b5ca @odersky added requires and ensuring methods.
odersky authored
219 def require(requirement: Boolean) {
220 if (!requirement)
221 throw new IllegalArgumentException("requirement failed")
222 }
223
a0476af 2nd round of clean ups (see r25285)
michelou authored
224 /** Tests an expression, throwing an `IllegalArgumentException` if false.
225 * This method is similar to `assert`, but blames the caller of the method
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
226 * for violating the condition.
227 *
4af7703 @retronym Address doc comment rot in the standard library.
retronym authored
228 * @param requirement the expression to test
229 * @param message a String to include in the failure message
c452268 @paulp Added some documentation to the methods in Pred...
paulp authored
230 */
b973195 @paulp Working on the inliner, discovered that a few k...
paulp authored
231 @inline final def require(requirement: Boolean, message: => Any) {
694b5ca @odersky added requires and ensuring methods.
odersky authored
232 if (!requirement)
233 throw new IllegalArgumentException("requirement failed: "+ message)
b83bbad @odersky *** empty log message ***
odersky authored
234 }
235
d1c0918 @odersky Made 3 classes in the standard library into value classes.
odersky authored
236 final class Ensuring[A](val __resultOfEnsuring: A) extends AnyVal {
bcc5eeb @paulp Fix binary breakage.
paulp authored
237 // `__resultOfEnsuring` must be a public val to allow inlining.
238 // See comments in ArrowAssoc for more.
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
239 @deprecated("Use `__resultOfEnsuring` instead", "2.10.0")
bcc5eeb @paulp Fix binary breakage.
paulp authored
240 def x = __resultOfEnsuring
241
24eb4c5 @adriaanm no need to add an x field to everything
adriaanm authored
242 def ensuring(cond: Boolean): A = { assert(cond); __resultOfEnsuring }
243 def ensuring(cond: Boolean, msg: => Any): A = { assert(cond, msg); __resultOfEnsuring }
244 def ensuring(cond: A => Boolean): A = { assert(cond(__resultOfEnsuring)); __resultOfEnsuring }
245 def ensuring(cond: A => Boolean, msg: => Any): A = { assert(cond(__resultOfEnsuring), msg); __resultOfEnsuring }
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
246 }
7fe2892 @odersky Split StringAdd into StringAdd and StringFormat
odersky authored
247 @inline implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x)
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
248
497e632 @odersky Added ??? and NotImplementedError because this ...
odersky authored
249 /** `???` can be used for marking methods that remain to be implemented.
250 * @throws A `NotImplementedError`
251 */
252 def ??? : Nothing = throw new NotImplementedError
253
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
254 // tupling ------------------------------------------------------------
67dfced @odersky added infix type constructors
odersky authored
255
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
256 type Pair[+A, +B] = Tuple2[A, B]
485a79a @odersky made pattern constructors termsymbols
odersky authored
257 object Pair {
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
258 def apply[A, B](x: A, y: B) = Tuple2(x, y)
7f4894c revert, predef doesn't know type "Some"
Burak Emir authored
259 def unapply[A, B](x: Tuple2[A, B]): Option[Tuple2[A, B]] = Some(x)
485a79a @odersky made pattern constructors termsymbols
odersky authored
260 }
67dfced @odersky added infix type constructors
odersky authored
261
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
262 type Triple[+A, +B, +C] = Tuple3[A, B, C]
485a79a @odersky made pattern constructors termsymbols
odersky authored
263 object Triple {
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
264 def apply[A, B, C](x: A, y: B, z: C) = Tuple3(x, y, z)
7f4894c revert, predef doesn't know type "Some"
Burak Emir authored
265 def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x)
485a79a @odersky made pattern constructors termsymbols
odersky authored
266 }
67dfced @odersky added infix type constructors
odersky authored
267
d1c0918 @odersky Made 3 classes in the standard library into value classes.
odersky authored
268 final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal {
bcc5eeb @paulp Fix binary breakage.
paulp authored
269 // `__leftOfArrow` must be a public val to allow inlining. The val
270 // used to be called `x`, but now goes by `__leftOfArrow`, as that
271 // reduces the chances of a user's writing `foo.__leftOfArrow` and
272 // being confused why they get an ambiguous implicit conversion
273 // error. (`foo.x` used to produce this error since both
274 // any2Ensuring and any2ArrowAssoc pimped an `x` onto everything)
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
275 @deprecated("Use `__leftOfArrow` instead", "2.10.0")
bcc5eeb @paulp Fix binary breakage.
paulp authored
276 def x = __leftOfArrow
277
24eb4c5 @adriaanm no need to add an x field to everything
adriaanm authored
278 @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y)
fb80a94 Implemented #988.
Geoffrey Washburn authored
279 def [B](y: B): Tuple2[A, B] = ->(y)
67dfced @odersky added infix type constructors
odersky authored
280 }
7fe2892 @odersky Split StringAdd into StringAdd and StringFormat
odersky authored
281 @inline implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x)
67dfced @odersky added infix type constructors
odersky authored
282
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
283 // printing and reading -----------------------------------------------
0196b0e @odersky (1) added readLong to Console.
odersky authored
284
285 def print(x: Any) = Console.print(x)
286 def println() = Console.println()
287 def println(x: Any) = Console.println(x)
77eb8fe @paulp Mopping up after the deprecation of exit and er...
paulp authored
288 def printf(text: String, xs: Any*) = Console.print(text.format(xs: _*))
626e389 @paulp Remedied a return type oops in the system package.
paulp authored
289
0196b0e @odersky (1) added readLong to Console.
odersky authored
290 def readLine(): String = Console.readLine()
5d782f2 @khernyo Closes SI-5066
khernyo authored
291 def readLine(text: String, args: Any*) = Console.readLine(text, args: _*)
0196b0e @odersky (1) added readLong to Console.
odersky authored
292 def readBoolean() = Console.readBoolean()
293 def readByte() = Console.readByte()
294 def readShort() = Console.readShort()
295 def readChar() = Console.readChar()
296 def readInt() = Console.readInt()
297 def readLong() = Console.readLong()
298 def readFloat() = Console.readFloat()
299 def readDouble() = Console.readDouble()
300 def readf(format: String) = Console.readf(format)
301 def readf1(format: String) = Console.readf1(format)
302 def readf2(format: String) = Console.readf2(format)
303 def readf3(format: String) = Console.readf3(format)
304
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
305 // views --------------------------------------------------------------
0c7b99f @adriaanm Revert several commits related to implicits/predef
adriaanm authored
306
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
307 implicit def exceptionWrapper(exc: Throwable) = new runtime.RichException(exc)
308 implicit def tuple2ToZippedOps[T1, T2](x: (T1, T2)) = new runtime.Tuple2Zipped.Ops(x)
309 implicit def tuple3ToZippedOps[T1, T2, T3](x: (T1, T2, T3)) = new runtime.Tuple3Zipped.Ops(x)
55b6094 @paulp Eliminate breaking relative names in source.
paulp authored
310 implicit def seqToCharSequence(xs: scala.collection.IndexedSeq[Char]): CharSequence = new runtime.SeqCharSequence(xs)
d003dee @paulp Working around the VerifyErrors.
paulp authored
311 implicit def arrayToCharSequence(xs: Array[Char]): CharSequence = new runtime.ArrayCharSequence(xs, 0, xs.length)
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
312
313 implicit def genericArrayOps[T](xs: Array[T]): ArrayOps[T] = (xs match {
314 case x: Array[AnyRef] => refArrayOps[AnyRef](x)
315 case x: Array[Boolean] => booleanArrayOps(x)
316 case x: Array[Byte] => byteArrayOps(x)
317 case x: Array[Char] => charArrayOps(x)
318 case x: Array[Double] => doubleArrayOps(x)
319 case x: Array[Float] => floatArrayOps(x)
320 case x: Array[Int] => intArrayOps(x)
321 case x: Array[Long] => longArrayOps(x)
322 case x: Array[Short] => shortArrayOps(x)
323 case x: Array[Unit] => unitArrayOps(x)
e1780e9 @paulp Made the additions to Predef described in #3762.
paulp authored
324 case null => null
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
325 }).asInstanceOf[ArrayOps[T]]
38dd94c @odersky Preparing for array switchover
odersky authored
326
4a727f3 @odersky Collections refactoring.
odersky authored
327 implicit def booleanArrayOps(xs: Array[Boolean]): ArrayOps[Boolean] = new ArrayOps.ofBoolean(xs)
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
328 implicit def byteArrayOps(xs: Array[Byte]): ArrayOps[Byte] = new ArrayOps.ofByte(xs)
329 implicit def charArrayOps(xs: Array[Char]): ArrayOps[Char] = new ArrayOps.ofChar(xs)
330 implicit def doubleArrayOps(xs: Array[Double]): ArrayOps[Double] = new ArrayOps.ofDouble(xs)
331 implicit def floatArrayOps(xs: Array[Float]): ArrayOps[Float] = new ArrayOps.ofFloat(xs)
332 implicit def intArrayOps(xs: Array[Int]): ArrayOps[Int] = new ArrayOps.ofInt(xs)
333 implicit def longArrayOps(xs: Array[Long]): ArrayOps[Long] = new ArrayOps.ofLong(xs)
334 implicit def refArrayOps[T <: AnyRef](xs: Array[T]): ArrayOps[T] = new ArrayOps.ofRef[T](xs)
335 implicit def shortArrayOps(xs: Array[Short]): ArrayOps[Short] = new ArrayOps.ofShort(xs)
336 implicit def unitArrayOps(xs: Array[Unit]): ArrayOps[Unit] = new ArrayOps.ofUnit(xs)
38dd94c @odersky Preparing for array switchover
odersky authored
337
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
338 // Primitive Widenings --------------------------------------------------------------
083f4dd @odersky fix arrays some more.
odersky authored
339
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
340 @deprecated("Use `.toShort` for explicit conversion and `Byte.byte2short` for implicit conversion", "2.10.0") def byte2short(x: Byte): Short = x.toShort
341 @deprecated("Use `.toInt` for explicit conversion and `Byte.byte2int` for implicit conversion", "2.10.0") def byte2int(x: Byte): Int = x.toInt
342 @deprecated("Use `.toLong` for explicit conversion and `Byte.byte2long for implicit conversion", "2.10.0") def byte2long(x: Byte): Long = x.toLong
343 @deprecated("Use `.toFloat` for explicit conversion and `Byte.byte2float` for implicit conversion", "2.10.0") def byte2float(x: Byte): Float = x.toFloat
344 @deprecated("Use `.toDouble` for explicit conversion and `Byte.byte2double` for implicit conversion", "2.10.0") def byte2double(x: Byte): Double = x.toDouble
6fa5484 @viktorklang Clarifying deprecation for implicit and explicit usage of the x2y's i…
viktorklang authored
345
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
346 @deprecated("Use `.toInt` for explicit conversion and `Short.short2int` for implicit conversion", "2.10.0") def short2int(x: Short): Int = x.toInt
347 @deprecated("Use `.toLong` for explicit conversion and `Short.short2long` for implicit conversion", "2.10.0") def short2long(x: Short): Long = x.toLong
348 @deprecated("Use `.toFloat` for explicit conversion and `Short.short2float` for implicit conversion", "2.10.0") def short2float(x: Short): Float = x.toFloat
349 @deprecated("Use `.toDouble` for explicit conversion and `Short.short2double` for implicit conversion", "2.10.0") def short2double(x: Short): Double = x.toDouble
6fa5484 @viktorklang Clarifying deprecation for implicit and explicit usage of the x2y's i…
viktorklang authored
350
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
351 @deprecated("Use `.toInt` for explicit conversion and `Char.char2int` for implicit conversion", "2.10.0") def char2int(x: Char): Int = x.toInt
352 @deprecated("Use `.toLong` for explicit conversion and `Char.char2long` for implicit conversion", "2.10.0") def char2long(x: Char): Long = x.toLong
353 @deprecated("Use `.toFloat` for explicit conversion and `Char.char2float` for implicit conversion", "2.10.0") def char2float(x: Char): Float = x.toFloat
354 @deprecated("Use `.toDouble` for explicit conversion and `Char.char2double` for implicit conversion", "2.10.0") def char2double(x: Char): Double = x.toDouble
6fa5484 @viktorklang Clarifying deprecation for implicit and explicit usage of the x2y's i…
viktorklang authored
355
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
356 @deprecated("Use `.toLong` for explicit conversion and `Int.int2long` for implicit conversion", "2.10.0") def int2long(x: Int): Long = x.toLong
357 @deprecated("Use `.toFloat` for explicit conversion and `Int.int2float` for implicit conversion", "2.10.0") def int2float(x: Int): Float = x.toFloat
358 @deprecated("Use `.toDouble` for explicit conversion and `Int.int2double` for implicit conversion", "2.10.0") def int2double(x: Int): Double = x.toDouble
6fa5484 @viktorklang Clarifying deprecation for implicit and explicit usage of the x2y's i…
viktorklang authored
359
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
360 @deprecated("Use `.toFloat` for explicit conversion and `Long.long2float` for implicit conversion", "2.10.0") def long2float(x: Long): Float = x.toFloat
361 @deprecated("Use `.toDouble` for explicit conversion and `Long.long2double` for implicit conversion", "2.10.0") def long2double(x: Long): Double = x.toDouble
6fa5484 @viktorklang Clarifying deprecation for implicit and explicit usage of the x2y's i…
viktorklang authored
362
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
363 @deprecated("Use `.toDouble` for explicit conversion and `Float.float2double` for implicit conversion", "2.10.0") def float2double(x: Float): Double = x.toDouble
96d7374 Capitalized type params in Predef, fixed bug in...
michelou authored
364
561a807 @paulp Interpreted absence of any objections in mailin...
paulp authored
365 // "Autoboxing" and "Autounboxing" ---------------------------------------------------
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
366
7a458d7 @paulp Modified all boxing methods to use java.lang.{P...
paulp authored
367 implicit def byte2Byte(x: Byte) = java.lang.Byte.valueOf(x)
368 implicit def short2Short(x: Short) = java.lang.Short.valueOf(x)
369 implicit def char2Character(x: Char) = java.lang.Character.valueOf(x)
370 implicit def int2Integer(x: Int) = java.lang.Integer.valueOf(x)
371 implicit def long2Long(x: Long) = java.lang.Long.valueOf(x)
372 implicit def float2Float(x: Float) = java.lang.Float.valueOf(x)
373 implicit def double2Double(x: Double) = java.lang.Double.valueOf(x)
374 implicit def boolean2Boolean(x: Boolean) = java.lang.Boolean.valueOf(x)
257a184 Refactored portability support
mihaylov authored
375
9b54520 @paulp Eliminated duplication among the Rich* wrappers...
paulp authored
376 // These next eight implicits exist solely to exclude AnyRef methods from the
377 // eight implicits above so that primitives are not coerced to AnyRefs. They
378 // only create such conflict for AnyRef methods, so the methods on the java.lang
379 // boxed types are unambiguously reachable.
380 implicit def byte2ByteConflict(x: Byte) = new AnyRef
381 implicit def short2ShortConflict(x: Short) = new AnyRef
382 implicit def char2CharacterConflict(x: Char) = new AnyRef
383 implicit def int2IntegerConflict(x: Int) = new AnyRef
384 implicit def long2LongConflict(x: Long) = new AnyRef
385 implicit def float2FloatConflict(x: Float) = new AnyRef
386 implicit def double2DoubleConflict(x: Double) = new AnyRef
387 implicit def boolean2BooleanConflict(x: Boolean) = new AnyRef
388
561a807 @paulp Interpreted absence of any objections in mailin...
paulp authored
389 implicit def Byte2byte(x: java.lang.Byte): Byte = x.byteValue
390 implicit def Short2short(x: java.lang.Short): Short = x.shortValue
391 implicit def Character2char(x: java.lang.Character): Char = x.charValue
392 implicit def Integer2int(x: java.lang.Integer): Int = x.intValue
393 implicit def Long2long(x: java.lang.Long): Long = x.longValue
394 implicit def Float2float(x: java.lang.Float): Float = x.floatValue
395 implicit def Double2double(x: java.lang.Double): Double = x.doubleValue
396 implicit def Boolean2boolean(x: java.lang.Boolean): Boolean = x.booleanValue
397
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
398 // Strings and CharSequences --------------------------------------------------------------
e72f0c7 @odersky Massive redesign so that: scala> "hi" == "hi".r...
odersky authored
399
7fe2892 @odersky Split StringAdd into StringAdd and StringFormat
odersky authored
400 @inline implicit def any2stringfmt(x: Any) = new runtime.StringFormat(x)
401 @inline implicit def augmentString(x: String): StringOps = new StringOps(x)
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
402 implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
403 implicit def unaugmentString(x: StringOps): String = x.repr
404
d6a184f @viktorklang Adding backticks to code in deprecation messages in Predef
viktorklang authored
405 @deprecated("Use `StringCanBuildFrom`", "2.10.0")
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
406 def stringCanBuildFrom: CanBuildFrom[String, Char, String] = StringCanBuildFrom
257a184 Refactored portability support
mihaylov authored
407
cf18d87 @paulp Optimization of Predef implicits.
paulp authored
408 implicit val StringCanBuildFrom: CanBuildFrom[String, Char, String] = new CanBuildFrom[String, Char, String] {
409 def apply(from: String) = apply()
410 def apply() = mutable.StringBuilder.newBuilder
d5b02c8 @odersky new arrays are done.
odersky authored
411 }
412
07c2955 @paulp Moved those bits of Predef into the scala packa...
paulp authored
413 // Type Constraints --------------------------------------------------------------
414
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
415 /**
416 * An instance of `A <:< B` witnesses that `A` is a subtype of `B`.
417 * Requiring an implicit argument of the type `A <:< B` encodes
418 * the generalized constraint `A <: B`.
c8dec98 @adriaanm documentation for conforms and friends
adriaanm authored
419 *
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
420 * @note we need a new type constructor `<:<` and evidence `conforms`,
421 * as reusing `Function1` and `identity` leads to ambiguities in
a0476af 2nd round of clean ups (see r25285)
michelou authored
422 * case of type errors (`any2stringadd` is inferred)
c8dec98 @adriaanm documentation for conforms and friends
adriaanm authored
423 *
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
424 * To constrain any abstract type T that's in scope in a method's
425 * argument list (not just the method's own type parameters) simply
a0476af 2nd round of clean ups (see r25285)
michelou authored
426 * add an implicit argument of type `T <:< U`, where `U` is the required
427 * upper bound; or for lower-bounds, use: `L <:< T`, where `L` is the
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
428 * required lower bound.
429 *
430 * In part contributed by Jason Zaugg.
c8dec98 @adriaanm documentation for conforms and friends
adriaanm authored
431 */
a2b0c26 @viktorklang Removing erronous quoting of implicitNotFound
viktorklang authored
432 @implicitNotFound(msg = "Cannot prove that ${From} <:< ${To}.")
2230bc9 @paulp Made <:< and =:= serializable.
paulp authored
433 sealed abstract class <:<[-From, +To] extends (From => To) with Serializable
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
434 private[this] final val singleton_<:< = new <:<[Any,Any] { def apply(x: Any): Any = x }
435 // not in the <:< companion object because it is also
436 // intended to subsume identity (which is no longer implicit)
437 implicit def conforms[A]: A <:< A = singleton_<:<.asInstanceOf[A <:< A]
a3aa801 @adriaanm quick fix for #2673: relaxed zipped on Tuple2/T...
adriaanm authored
438
c8dec98 @adriaanm documentation for conforms and friends
adriaanm authored
439 /** An instance of `A =:= B` witnesses that the types `A` and `B` are equal.
440 *
a0476af 2nd round of clean ups (see r25285)
michelou authored
441 * @see `<:<` for expressing subtyping constraints
c8dec98 @adriaanm documentation for conforms and friends
adriaanm authored
442 */
a2b0c26 @viktorklang Removing erronous quoting of implicitNotFound
viktorklang authored
443 @implicitNotFound(msg = "Cannot prove that ${From} =:= ${To}.")
2230bc9 @paulp Made <:< and =:= serializable.
paulp authored
444 sealed abstract class =:=[From, To] extends (From => To) with Serializable
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
445 private[this] final val singleton_=:= = new =:=[Any,Any] { def apply(x: Any): Any = x }
a3aa801 @adriaanm quick fix for #2673: relaxed zipped on Tuple2/T...
adriaanm authored
446 object =:= {
6c87275 @paulp Avoided a ton of unnecessary garbage by creatin...
paulp authored
447 implicit def tpEquals[A]: A =:= A = singleton_=:=.asInstanceOf[A =:= A]
a3aa801 @adriaanm quick fix for #2673: relaxed zipped on Tuple2/T...
adriaanm authored
448 }
449
f578ff8 @paulp As a brief diversion from real work, implemente...
paulp authored
450 /** A type for which there is always an implicit value.
37d6ffb @heathermiller Corrects links in API documentation
heathermiller authored
451 * @see [[scala.Array$]], method `fallbackCanBuildFrom`
d5b02c8 @odersky new arrays are done.
odersky authored
452 */
453 class DummyImplicit
454
455 object DummyImplicit {
456
a0476af 2nd round of clean ups (see r25285)
michelou authored
457 /** An implicit value yielding a `DummyImplicit`.
37d6ffb @heathermiller Corrects links in API documentation
heathermiller authored
458 * @see [[scala.Array$]], method `fallbackCanBuildFrom`
d5b02c8 @odersky new arrays are done.
odersky authored
459 */
460 implicit def dummyImplicit: DummyImplicit = new DummyImplicit
461 }
6ab8129 *** empty log message ***
Matthias Zenger authored
462 }
Something went wrong with that request. Please try again.