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
| // Proposed ehancement to ScalaTest to surface more info about compiler errors | |
| // Existing syntax | |
| // Assertions: | |
| assertDoesNotCompile("val i: String = 1") // Expects either a type or parse error | |
| assertTypeError("val i: String = 1") // Expects just a type error (not a parse error) | |
| assertCompiles("val i: Int = 1") // Expects no error during compilation | |
| // Matchers: | |
| "val i: String = 1" shouldNot compile // Expects either a type or parse error | |
| "val i: String = 1" shouldNot typeCheck // Expects either a type 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
| :paste | |
| type ErrorMessage = String | |
| trait LeftBiased | |
| trait RightBiased | |
| sealed abstract class Or[+G, +B] extends LeftBiased { | |
| def map[H](f: G => H): H Or B |
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 org.scalatest.Assertions._ | |
| import org.scalatest.Assertions._ | |
| scala> val x = 1 | |
| x: Int = 1 | |
| scala> assert(List(1, 2, 3).contains(x) && x > 1) | |
| org.scalatest.exceptions.TestFailedException: List(1, 2, 3) contained 1, but 1 was not greater than 1 | |
| at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:541) | |
| at org.scalatest.Assertions$.newAssertionFailedException(Assertions.scala:1414) |
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
| // If you paste this code into the Scala interpretter with ScalaUtils on the path: | |
| List(1) contains 1 | |
| List(1) contains "1" | |
| import scala.collection.GenSeq | |
| implicit class Containz[A](xs: GenSeq[A]) { | |
| def containz[B <: A](ele: B): Boolean = xs.exists(_ == ele) | |
| } |
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> List(1, 2, 3) contains 1 | |
| res5: Boolean = true | |
| scala> List(1, 2, 3) contains "1" | |
| res6: Boolean = false | |
| scala> import scala.collection.GenSeq | |
| import scala.collection.GenSeq | |
| scala> implicit class Containz[A](xs: GenSeq[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
| // TEST 1 - FAIL | |
| package foo | |
| import org.scalautils._ | |
| import org.scalatest._ | |
| import Matchers._ | |
| import TypeCheckedTripleEquals._ | |
| class Work { | |
| 1 should === ("aoeu") |
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
| // Questions about \/ and Validation | |
| object scalaz { | |
| /* | |
| Thanks for the great explanation, Tony. This explanation as well as the answers | |
| that came back from Runar and Mark nudged my thinking in a different direction. | |
| The feeling I get is that there's a monad inside of Validation trying to get out. | |
| It looks like Validation would be monadic just from its shape, and users seem to | |
| want to use them in for expressions. I now see that a Validation monad would need |
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
| // Here is code that can be pasted into the REPL | |
| import scalaz._ | |
| import Scalaz._ | |
| import org.scalautils._ | |
| def all[F[_]: Applicative, A](s: String, parsers: List[String => F[A]]): F[List[A]] = parsers.traverse(p => p(s)) | |
| implicit class BadDog[G, B](or: Or[G, B]) { | |
| def badMap[C](bToC: B => C): G Or C = or.swap.map(bToC).swap | |
| } | |
| trait LowPriorityImplicit { |
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
| // Here's code that can be pasted into an interpreter sesssion: | |
| import scalaz._ | |
| import Scalaz._ | |
| import org.scalautils._ | |
| def all[F[_]: Applicative, A](s: String, parsers: List[String => F[A]]): F[List[A]] = parsers.traverse(p => p(s)) | |
| implicit class BadDog[G, B](or: Or[G, B]) { | |
| def badMap[C](bToC: B => C): G Or C = or.swap.map(bToC).swap | |
| } | |
| def toIntE(s: String): Int Or ErrorMessage = attempt(s.toInt).badMap(_.getMessage) | |
| def one: String => (Int Or List[ErrorMessage]) = s => toIntE(s).badMap(List(_)) |
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
| /** | |
| * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> | |
| */ | |
| package akka.cluster | |
| import scala.collection.immutable.SortedSet | |
| import com.typesafe.config.ConfigFactory | |
| import akka.remote.testkit.MultiNodeConfig | |
| import akka.remote.testkit.MultiNodeSpec | |
| import akka.testkit._ |
NewerOlder