This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package object foobar { | |
case class A | |
case class B | |
def main(args: Array[String]) { | |
println("Hello") | |
} | |
} | |
// scalac package.scala | |
// scala foobar.package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.DynamicVariable | |
object JssonBuilder { | |
private val status = new DynamicVariable[Map[String, Any]](null) | |
class ArrowOperatorExtension(key: String) { | |
//Warning: this could cause unexpected behavior | |
def ->(value: Any): (String, Any) = { | |
val result = (key, value) | |
status.value = status.value + result | |
result | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> { | |
| import scala.io._ | |
| val r = Source.fromFile("file.txt") | |
| println(r.getLines().toList) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import foo._ | |
object A { | |
def main(args: Array[String]) { | |
println(plus(1)) | |
println(plus(1, 3)) | |
} | |
} | |
//scalac package.scala | |
//scalac A.scala | |
//scala A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def matchType[A:ClassManifest](value: Any): Boolean = { | |
val classAny: Class[_] = value match { | |
case _:Byte=> classOf[Byte] | |
case _:Short => classOf[Short] | |
case _:Int => classOf[Int] | |
case _:Long => classOf[Long] | |
case _:Float => classOf[Float] | |
case _:Double => classOf[Double] | |
case _:Char => classOf[Char] | |
case _:Boolean => classOf[Boolean] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ByNameParams { | |
private def multiply(x: => Int) : Int = x * 2 | |
def hello { | |
multiply(100) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import PimpGrepToCollection._ | |
import PimpGrepToCollection._ | |
scala> List("123", "156", "C").grep("\\d"){_.toInt} | |
res0: List[Int] = List(123, 156) | |
scala> Set("123", "456", "XXX").grep("\\d"){_.toInt} | |
res1: scala.collection.immutable.Set[Int] = Set(123, 456) | |
scala> Vector("A", "100", "XXX").grep("\\d"){_.toInt} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ImplicitRecursion { | |
abstract class Nat | |
class Zero extends Nat | |
class Succ[T <: Nat] extends Nat | |
type _0 = Zero | |
type _1 = Succ[_0] | |
type _2 = Succ[_1] | |
type _3 = Succ[_2] | |
type _4 = Succ[_3] | |
type _5 = Succ[_4] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.reflect.BeanProperty | |
trait Bean { | |
@BeanProperty var x: Int | |
} | |
class BeanImpl(@BeanProperty var x: Int) extends Bean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
private def foo { | |
Foo.foo | |
} | |
} | |
object Foo { | |
private def foo { | |
println("foo") | |
} | |
} |