Permalink
Browse files

Added a pinch of compiler plugin, a dose of compilets, a laundried- a…

…nd trimmed-down-scala library and an sbt build project
  • Loading branch information...
1 parent effe654 commit a7cc370750fe23e6e0439368cbe94a00fa06393d @ochafik committed May 9, 2012
Showing with 5,210 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +4 −0 CompilerPlugin/src/main/resources/scalac-plugin.xml
  3. +53 −0 CompilerPlugin/src/main/scala/scalight/plugin/ScalightPlugin.scala
  4. +23 −0 Compilets/src/main/scala/scalight/compilets/Collection.scala
  5. +35 −0 RuntimeLibrary/LICENSE
  6. +15 −0 RuntimeLibrary/README.md
  7. +135 −0 RuntimeLibrary/src/main/scala/scala/Function.scala
  8. +43 −0 RuntimeLibrary/src/main/scala/scala/Function0.scala
  9. +60 −0 RuntimeLibrary/src/main/scala/scala/Function1.scala
  10. +38 −0 RuntimeLibrary/src/main/scala/scala/Function10.scala
  11. +38 −0 RuntimeLibrary/src/main/scala/scala/Function11.scala
  12. +38 −0 RuntimeLibrary/src/main/scala/scala/Function12.scala
  13. +38 −0 RuntimeLibrary/src/main/scala/scala/Function13.scala
  14. +38 −0 RuntimeLibrary/src/main/scala/scala/Function14.scala
  15. +38 −0 RuntimeLibrary/src/main/scala/scala/Function15.scala
  16. +38 −0 RuntimeLibrary/src/main/scala/scala/Function16.scala
  17. +38 −0 RuntimeLibrary/src/main/scala/scala/Function17.scala
  18. +38 −0 RuntimeLibrary/src/main/scala/scala/Function18.scala
  19. +38 −0 RuntimeLibrary/src/main/scala/scala/Function19.scala
  20. +57 −0 RuntimeLibrary/src/main/scala/scala/Function2.scala
  21. +38 −0 RuntimeLibrary/src/main/scala/scala/Function20.scala
  22. +38 −0 RuntimeLibrary/src/main/scala/scala/Function21.scala
  23. +38 −0 RuntimeLibrary/src/main/scala/scala/Function22.scala
  24. +38 −0 RuntimeLibrary/src/main/scala/scala/Function3.scala
  25. +38 −0 RuntimeLibrary/src/main/scala/scala/Function4.scala
  26. +38 −0 RuntimeLibrary/src/main/scala/scala/Function5.scala
  27. +38 −0 RuntimeLibrary/src/main/scala/scala/Function6.scala
  28. +38 −0 RuntimeLibrary/src/main/scala/scala/Function7.scala
  29. +38 −0 RuntimeLibrary/src/main/scala/scala/Function8.scala
  30. +38 −0 RuntimeLibrary/src/main/scala/scala/Function9.scala
  31. +314 −0 RuntimeLibrary/src/main/scala/scala/Option.scala
  32. +233 −0 RuntimeLibrary/src/main/scala/scala/PartialFunction.scala
  33. +53 −0 RuntimeLibrary/src/main/scala/scala/Product.scala
  34. +47 −0 RuntimeLibrary/src/main/scala/scala/Product1.scala
  35. +92 −0 RuntimeLibrary/src/main/scala/scala/Product10.scala
  36. +97 −0 RuntimeLibrary/src/main/scala/scala/Product11.scala
  37. +102 −0 RuntimeLibrary/src/main/scala/scala/Product12.scala
  38. +107 −0 RuntimeLibrary/src/main/scala/scala/Product13.scala
  39. +112 −0 RuntimeLibrary/src/main/scala/scala/Product14.scala
  40. +117 −0 RuntimeLibrary/src/main/scala/scala/Product15.scala
  41. +122 −0 RuntimeLibrary/src/main/scala/scala/Product16.scala
  42. +127 −0 RuntimeLibrary/src/main/scala/scala/Product17.scala
  43. +132 −0 RuntimeLibrary/src/main/scala/scala/Product18.scala
  44. +137 −0 RuntimeLibrary/src/main/scala/scala/Product19.scala
  45. +52 −0 RuntimeLibrary/src/main/scala/scala/Product2.scala
  46. +142 −0 RuntimeLibrary/src/main/scala/scala/Product20.scala
  47. +147 −0 RuntimeLibrary/src/main/scala/scala/Product21.scala
  48. +152 −0 RuntimeLibrary/src/main/scala/scala/Product22.scala
  49. +57 −0 RuntimeLibrary/src/main/scala/scala/Product3.scala
  50. +62 −0 RuntimeLibrary/src/main/scala/scala/Product4.scala
  51. +67 −0 RuntimeLibrary/src/main/scala/scala/Product5.scala
  52. +72 −0 RuntimeLibrary/src/main/scala/scala/Product6.scala
  53. +77 −0 RuntimeLibrary/src/main/scala/scala/Product7.scala
  54. +82 −0 RuntimeLibrary/src/main/scala/scala/Product8.scala
  55. +87 −0 RuntimeLibrary/src/main/scala/scala/Product9.scala
  56. +23 −0 RuntimeLibrary/src/main/scala/scala/Tuple1.scala
  57. +32 −0 RuntimeLibrary/src/main/scala/scala/Tuple10.scala
  58. +33 −0 RuntimeLibrary/src/main/scala/scala/Tuple11.scala
  59. +35 −0 RuntimeLibrary/src/main/scala/scala/Tuple12.scala
  60. +36 −0 RuntimeLibrary/src/main/scala/scala/Tuple13.scala
  61. +37 −0 RuntimeLibrary/src/main/scala/scala/Tuple14.scala
  62. +38 −0 RuntimeLibrary/src/main/scala/scala/Tuple15.scala
  63. +39 −0 RuntimeLibrary/src/main/scala/scala/Tuple16.scala
  64. +40 −0 RuntimeLibrary/src/main/scala/scala/Tuple17.scala
  65. +41 −0 RuntimeLibrary/src/main/scala/scala/Tuple18.scala
  66. +42 −0 RuntimeLibrary/src/main/scala/scala/Tuple19.scala
  67. +30 −0 RuntimeLibrary/src/main/scala/scala/Tuple2.scala
  68. +43 −0 RuntimeLibrary/src/main/scala/scala/Tuple20.scala
  69. +44 −0 RuntimeLibrary/src/main/scala/scala/Tuple21.scala
  70. +45 −0 RuntimeLibrary/src/main/scala/scala/Tuple22.scala
  71. +25 −0 RuntimeLibrary/src/main/scala/scala/Tuple3.scala
  72. +26 −0 RuntimeLibrary/src/main/scala/scala/Tuple4.scala
  73. +27 −0 RuntimeLibrary/src/main/scala/scala/Tuple5.scala
  74. +28 −0 RuntimeLibrary/src/main/scala/scala/Tuple6.scala
  75. +29 −0 RuntimeLibrary/src/main/scala/scala/Tuple7.scala
  76. +30 −0 RuntimeLibrary/src/main/scala/scala/Tuple8.scala
  77. +31 −0 RuntimeLibrary/src/main/scala/scala/Tuple9.scala
  78. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction0.scala
  79. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction1.scala
  80. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction10.scala
  81. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction11.scala
  82. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction12.scala
  83. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction13.scala
  84. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction14.scala
  85. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction15.scala
  86. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction16.scala
  87. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction17.scala
  88. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction18.scala
  89. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction19.scala
  90. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction2.scala
  91. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction20.scala
  92. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction21.scala
  93. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction22.scala
  94. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction3.scala
  95. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction4.scala
  96. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction5.scala
  97. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction6.scala
  98. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction7.scala
  99. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction8.scala
  100. +14 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractFunction9.scala
  101. +72 −0 RuntimeLibrary/src/main/scala/scala/runtime/AbstractPartialFunction.scala
  102. +4 −1 StaticLibrary/src/main/scala/scalight/collection/package.scala
  103. +83 −0 project/ScalightBuild.scala
View
@@ -0,0 +1 @@
+.DS_Store
@@ -0,0 +1,4 @@
+<plugin>
+ <name>Scalaxy</name>
+ <classname>scalaxy.plugin.ScalaxyPlugin</classname>
+</plugin>
@@ -0,0 +1,53 @@
+/*
+ * ScalaCL - putting Scala on the GPU with JavaCL / OpenCL
+ * http://scalacl.googlecode.com/
+ *
+ * Copyright (c) 2009-2010, Olivier Chafik (http://ochafik.free.fr/)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Olivier Chafik nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package scalight.plugin
+
+import scalaxy.pluginBase._
+import scalaxy.plugin._
+
+import scala.tools.nsc.Global
+
+object ScalightPluginDef extends ScalaxyPluginDefLike {
+ override def envVarPrefix = "SCALIGHT_"
+
+ override def matchActionHolders = Seq(
+ scalight.compilets.Collection
+ )
+}
+
+class ScalightPlugin(override val global: Global)
+extends PluginBase(global, ScalightPluginDef)
+
+object Compile extends CompilerMain {
+ override def pluginDef = ScalightPluginDef
+ override def commandName = "scalight"
+}
+
@@ -0,0 +1,23 @@
+package scalight; package compilets
+
+import scalaxy.macros._
+//import scalaxy.matchers._
+
+object Collection extends scalaxy.Compilet
+{
+ import scalight.collection._
+ import scalight.collection.{ List => SList }
+
+
+ def listForeach[T : TypeTag, U : TypeTag](l: SList[T], body: U) = replace(
+ l.foreach(v => body),
+ {
+ val it = l.iterator()
+ while (it.hasNext()) {
+ val v = it.next
+ body
+ }
+ }
+ )
+ // TODO...
+}
View
@@ -0,0 +1,35 @@
+SCALA LICENSE
+
+Copyright (c) 2002-2011 EPFL, Lausanne, unless otherwise specified.
+All rights reserved.
+
+This software was developed by the Programming Methods Laboratory of the
+Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland.
+
+Permission to use, copy, modify, and distribute this software in source
+or binary form for any purpose with or without fee is hereby granted,
+provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of the EPFL nor the names of its contributors
+ may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
View
@@ -0,0 +1,15 @@
+This is a trimmed-down version of the Scala library (see LICENSE for copyright information).
+
+As a first step, it's probably better not to get rid of Product, Tuples & Functions.
+
+Source taken from Scala 2.10.0-SNAPSHOT roughly as of the 1st May 2012, with the following changes :
+* Commented @specialized annotations
+* Renamed scala package to scalaLight (see TODO below)
+* Changed scala.Product.productIterator to return Array[Any]
+
+TODO
+====
+
+Using a tool such as maven-shade-plugin, relocate / rename the following :
+* scalaLight package to scala
+* Product.productIterator2 to Product.productIterator
@@ -0,0 +1,135 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+
+
+package scalaLight
+
+/** A module defining utility methods for higher-order functional programming.
+ *
+ * @author Martin Odersky
+ * @version 1.0, 29/11/2006
+ */
+object Function {
+ /** Given a sequence of functions `f,,1,,`, ..., `f,,n,,`, return the
+ * function `f,,1,, andThen ... andThen f,,n,,`.
+ *
+ * @param fs The given sequence of functions
+ * @return ...
+ */
+ def chain[a](fs: Seq[a => a]): a => a = { x => (x /: fs) ((x, f) => f(x)) }
+
+ /** The constant function */
+ def const[T, U](x: T)(y: U): T = x
+
+ /** Turns a function `A => Option[B]` into a `PartialFunction[A, B]`.
+ *
+ * TODO: check if the paragraph below is still correct
+ * '''Important note''': this transformation implies the original function
+ * will be called 2 or more times on each logical invocation, because the
+ * only way to supply an implementation of `isDefinedAt` is to call the
+ * function and examine the return value.
+ *
+ * @param f a function `T => Option[R]`
+ * @return a partial function defined for those inputs where
+ * f returns `Some(_)` and undefined where `f` returns `None`.
+ * @see [[scala.PartialFunction#lift]]
+ */
+ //def unlift[T, R](f: T => Option[R]): PartialFunction[T, R] = PartialFunction.unlifted(f)
+
+ /** Uncurrying for functions of arity 2. This transforms a unary function
+ * returning another unary function into a function of arity 2.
+ */
+ def uncurried[a1, a2, b](f: a1 => a2 => b): (a1, a2) => b = {
+ (x1, x2) => f(x1)(x2)
+ }
+
+ /** Uncurrying for functions of arity 3.
+ */
+ def uncurried[a1, a2, a3, b](f: a1 => a2 => a3 => b): (a1, a2, a3) => b = {
+ (x1, x2, x3) => f(x1)(x2)(x3)
+ }
+
+ /** Uncurrying for functions of arity 4.
+ */
+ def uncurried[a1, a2, a3, a4, b](f: a1 => a2 => a3 => a4 => b): (a1, a2, a3, a4) => b = {
+ (x1, x2, x3, x4) => f(x1)(x2)(x3)(x4)
+ }
+
+ /** Uncurrying for functions of arity 5.
+ */
+ def uncurried[a1, a2, a3, a4, a5, b](f: a1 => a2 => a3 => a4 => a5 => b): (a1, a2, a3, a4, a5) => b = {
+ (x1, x2, x3, x4, x5) => f(x1)(x2)(x3)(x4)(x5)
+ }
+
+ /** Tupling for functions of arity 2. This transforms a function
+ * of arity 2 into a unary function that takes a pair of arguments.
+ *
+ * @note These functions are slotted for deprecation, but it is on
+ * hold pending superior type inference for tupling anonymous functions.
+ *
+ * @param f ...
+ * @return ...
+ */
+ // @deprecated("Use `f.tupled` instead")
+ def tupled[a1, a2, b](f: (a1, a2) => b): Tuple2[a1, a2] => b = {
+ case Tuple2(x1, x2) => f(x1, x2)
+ }
+
+ /** Tupling for functions of arity 3. This transforms a function
+ * of arity 3 into a unary function that takes a triple of arguments.
+ */
+ // @deprecated("Use `f.tupled` instead")
+ def tupled[a1, a2, a3, b](f: (a1, a2, a3) => b): Tuple3[a1, a2, a3] => b = {
+ case Tuple3(x1, x2, x3) => f(x1, x2, x3)
+ }
+
+ /** Tupling for functions of arity 4. This transforms a function
+ * of arity 4 into a unary function that takes a 4-tuple of arguments.
+ */
+ // @deprecated("Use `f.tupled` instead")
+ def tupled[a1, a2, a3, a4, b](f: (a1, a2, a3, a4) => b): Tuple4[a1, a2, a3, a4] => b = {
+ case Tuple4(x1, x2, x3, x4) => f(x1, x2, x3, x4)
+ }
+
+ /** Tupling for functions of arity 5. This transforms a function
+ * of arity 5 into a unary function that takes a 5-tuple of arguments.
+ */
+ // @deprecated("Use `f.tupled` instead")
+ def tupled[a1, a2, a3, a4, a5, b](f: (a1, a2, a3, a4, a5) => b): Tuple5[a1, a2, a3, a4, a5] => b = {
+ case Tuple5(x1, x2, x3, x4, x5) => f(x1, x2, x3, x4, x5)
+ }
+
+ /** Un-tupling for functions of arity 2. This transforms a function taking
+ * a pair of arguments into a binary function which takes each argument separately.
+ */
+ def untupled[a1, a2, b](f: Tuple2[a1, a2] => b): (a1, a2) => b = {
+ (x1, x2) => f(Tuple2(x1, x2))
+ }
+
+ /** Un-tupling for functions of arity 3. This transforms a function taking
+ * a triple of arguments into a ternary function which takes each argument separately.
+ */
+ def untupled[a1, a2, a3, b](f: Tuple3[a1, a2, a3] => b): (a1, a2, a3) => b = {
+ (x1, x2, x3) => f(Tuple3(x1, x2, x3))
+ }
+
+ /** Un-tupling for functions of arity 4. This transforms a function taking
+ * a 4-tuple of arguments into a function of arity 4 which takes each argument separately.
+ */
+ def untupled[a1, a2, a3, a4, b](f: Tuple4[a1, a2, a3, a4] => b): (a1, a2, a3, a4) => b = {
+ (x1, x2, x3, x4) => f(Tuple4(x1, x2, x3, x4))
+ }
+
+ /** Un-tupling for functions of arity 5. This transforms a function taking
+ * a 5-tuple of arguments into a function of arity 5 which takes each argument separately.
+ */
+ def untupled[a1, a2, a3, a4, a5, b](f: Tuple5[a1, a2, a3, a4, a5] => b): (a1, a2, a3, a4, a5) => b = {
+ (x1, x2, x3, x4, x5) => f(Tuple5(x1, x2, x3, x4, x5))
+ }
+}
@@ -0,0 +1,43 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+// GENERATED CODE: DO NOT EDIT.
+// genprod generated these sources at: Mon Apr 30 07:46:11 PDT 2012
+
+package scalaLight
+
+
+/** A function of 0 parameters.
+ *
+ * In the following example, the definition of javaVersion is a
+ * shorthand for the anonymous class definition anonfun0:
+ *
+ * {{{
+ * object Main extends App {
+ * val javaVersion = () => sys.props("java.version")
+ *
+ * val anonfun0 = new Function0[String] {
+ * def apply(): String = sys.props("java.version")
+ * }
+ * assert(javaVersion() == anonfun0())
+ * }
+ * }}}
+ *
+ * Note that `Function1` does not define a total function, as might
+ * be suggested by the existence of [[scala.PartialFunction]]. The only
+ * distinction between `Function1` and `PartialFunction` is that the
+ * latter can specify inputs which it will not handle.
+
+ */
+trait Function0[/*@specialized*/ +R] extends AnyRef { self =>
+ /** Apply the body of this function to the arguments.
+ * @return the result of function application.
+ */
+ def apply(): R
+
+ override def toString() = "<function0>"
+}
@@ -0,0 +1,60 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.
+
+package scalaLight
+
+
+/** A function of 1 parameter.
+ *
+ * In the following example, the definition of succ is a
+ * shorthand for the anonymous class definition anonfun1:
+ *
+ * {{{
+ * object Main extends App {
+ * val succ = (x: Int) => x + 1
+ * val anonfun1 = new Function1[Int, Int] {
+ * def apply(x: Int): Int = x + 1
+ * }
+ * assert(succ(0) == anonfun1(0))
+ * }
+ * }}}
+ *
+ * Note that `Function1` does not define a total function, as might
+ * be suggested by the existence of [[scala.PartialFunction]]. The only
+ * distinction between `Function1` and `PartialFunction` is that the
+ * latter can specify inputs which it will not handle.
+
+ */
+@annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.")
+trait Function1[/*@specialized(scala.Int, scala.Long, scala.Float, scala.Double, scala.AnyRef)*/ -T1, /*@specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double, scala.AnyRef)*/ +R] extends AnyRef { self =>
+ /** Apply the body of this function to the argument.
+ * @return the result of function application.
+ */
+ def apply(v1: T1): R
+
+ /** Composes two instances of Function1 in a new Function1, with this function applied last.
+ *
+ * @tparam A the type to which function `g` can be applied
+ * @param g a function A => T1
+ * @return a new function `f` such that `f(x) == apply(g(x))`
+ */
+ def compose[A](g: scalaLight.Function1[A, T1]) = new scalaLight.Function1[A, R] {
+ override def apply(x: A) = Function1.this.apply(g(x))
+ }
+
+ /** Composes two instances of Function1 in a new Function1, with this function applied first.
+ *
+ * @tparam A the result type of function `g`
+ * @param g a function R => A
+ * @return a new function `f` such that `f(x) == g(apply(x))`
+ */
+ def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) }
+
+ override def toString() = "<function1>"
+}
Oops, something went wrong.

0 comments on commit a7cc370

Please sign in to comment.