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
| case class Cat( | |
| name: String, | |
| age: Int, | |
| weight: Int, | |
| food: String, | |
| likesMe: Boolean) | |
| val real = Cat("Garfield", 11, 8, "lasagna", false) | |
| val wish = real.copy(likesMe = true) |
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 Looping { | |
| val l = 1000 | |
| val l2 = l * l | |
| val l3 = l * l * l | |
| def main(args: Array[String]): Unit = { | |
| warmup() | |
| measure() | |
| } | |
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
| trait Plus1[A] { | |
| def plus(a: A, b: A): A | |
| } | |
| object Plus1 { | |
| implicit val LongPlus1 = new Plus1[Long] { | |
| def plus(a: Long, b: Long) = a + b | |
| } | |
| } | |
| trait Plus2[@specialized 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
| testOptions <+= crossTarget { ct => | |
| Tests.Setup(() => { System.setProperty("specs2.outDir", ct.getAbsolutePath); () }) | |
| } |
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 de.johoop.jacoco4sbt._ | |
| import JacocoPlugin._ | |
| organization := "my.organization" | |
| scalaVersion := "2.9.1" | |
| name := "my-project" | |
| seq(jacoco.settings : _*) |
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
| [error] package.scala:4: macros cannot be partially applied | |
| [error] def mf(args: Any*): String = sc.f(args:_*).stripMargin | |
| [error] ^ |
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> def f[A](x: A, xs: List[A]): List[A] = x :: xs | |
| f: [A](x: A, xs: List[A])List[A] | |
| scala> def g[A](x: A)(xs: List[A]): List[A] = x :: xs | |
| g: [A](x: A)(xs: List[A])List[A] | |
| scala> f(3, _) | |
| <console>:9: error: missing parameter type for expanded function ((x$1) => f(3, x$1)) | |
| f(3, _) | |
| ^ |
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
| Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_11). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> trait Meep { type Moop; def f: Moop } | |
| defined trait Meep | |
| scala> def fnord(a: Meep): a.Moop = a.f | |
| fnord: (a: Meep)a.Moop |
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 java.lang.Character.{isWhitespace, charCount} | |
| implicit class SuperString(str: String) extends AnyVal { | |
| def isBlank: Boolean = { | |
| @tailrec def check(index: Int): Boolean = | |
| if (index >= str.length) true | |
| else { | |
| val cp = str.codePointAt(index) | |
| if (isWhitespace(cp)) check(index + charCount(cp)) else false | |
| } |
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 org.scalacheck._, Prop.forAll, Gen._, Arbitrary._ | |
| object MeepSpec extends Properties("Meep") { | |
| case class Meep(id: Int, name: String) | |
| implicit lazy val arbMeep: Arbitrary[Meep] = Arbitrary(for (i <- arbitrary[Int]; n <- alphaStr) yield Meep(i, n)) | |
| // using ScalaCheck 1.12.5, this outlandish property would have passed: | |
| property("meep1") = forAll { (f: Meep => Meep, m1: Meep, m2: Meep) => f(m1) == f(m2) } | |
| // using ScalaCheck 1.13.0, we have to define how function input influences function output via an instance of Cogen: |
OlderNewer