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
| receive("hallo") { | |
| case "hallo" => "selber" // selber should not be evaluated at this point | |
| } // result Some(selber) |
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 translate(coord: (Int, Int), str: String) = (coord._1 + 1, coord._2 - 1) -> str | |
| translate: (coord: (Int, Int), str: String)((Int, Int), String) | |
| scala> (1, 1) -> "test" :: Nil map translate | |
| <console>:9: error: type mismatch; | |
| found : ((Int, Int), String) => ((Int, Int), String) | |
| required: ((Int, Int), java.lang.String) => ? | |
| (1, 1) -> "test" :: Nil map translate |
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
| ... problem.scala:6: type mismatch; | |
| [error] found : ((Int, Int), scawtor.serial.Cell) => Boolean | |
| [error] required: ((Int, Int), scawtor.serial.Cell) => Boolean | |
| [error] def neighboursDo(x: Int, y: Int)(fun: ((Int, Int), Cell) => Boolean): Unit = random.shuffle(neighboursFor(x, y)).exists(fun) |
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 Wubs { | |
| def WUB(wub: Wubs = this) = this | |
| def W(wub: Wubs = this) = this | |
| def WEEOOOOO(wub: Wubs = this) = this | |
| def -(wub: Wubs = this) = this | |
| } | |
| object WUB extends Wubs | |
| object W extends Wubs | |
| WUB WUB WUB WEEOOOOO W-W-W-W-WUB WUB WUB |
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 seqPlusHead[S <: Seq[T], T](seq: S): (S, T) = seq -> seq.head | |
| seqPlusHead[List[String], String](List("Hallo", "Welt")) | |
| // -> (List[String], String) = (List(Hallo, Welt),Hallo) | |
| def onlySeqPlusHead[Seq[T], T](seq: Seq[T]) = seqPlusHead[Seq[T], T](seq) | |
| // error: type arguments [Seq[T],T] do not conform to method seqPlusHead's type parameter bounds [S <: Seq[T],T] | |
| // def onlySeqPlusHead[Seq[T], T](seq: Seq[T]) = seqPlusHead[Seq[T], T](seq) | |
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
| implicit def seqReader[Seq[T], T](implicit reader: TwpReadable[T]): TwpReadable[Seq[T]] = | |
| new SequenceReader[Seq[T], T] { | |
| def map(in: Input) = reader read in | |
| def canMap(in: Input) = reader.isDefinedAt(in) | |
| } |
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
| describe("Unions") { | |
| trait TermUnion[T] | |
| trait Expression { /* ... */ } | |
| object TermUnion { | |
| implicit object DoubleWitness extends Union[Double] | |
| implicit object ExpressionWitness extends Union[Expression] | |
| } | |
| /** Only accepts union types Double and Expression. */ |
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
| [33.37] failure: identifier expected | |
| any defined by operation parameters; | |
| ^ |
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 MessageCompanion[S <: Message, T] /* ... */ { | |
| def unapply(in: Input): Option[T] = { | |
| if (isDefinedAt(in)) { | |
| val result = Some(read(in)) | |
| checkComplete(in) | |
| result | |
| } else None | |
| } | |
| def read(in: Input): T |
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
| type Path = Seq[String] | |
| class Changed(val path: Path, val fileName: String) extends Message { | |
| def write = Changed.tag.msg #:: path #:: fileName #:: Output | |
| } | |
| object Changed extends MessageCompanion[(Path, String)] { | |
| def tag = 0 | |
| def apply(path: Path, fileName: String) = new Changed(path, fileName) | |
| def read(implicit in: Input) = (sequence[Path], string) |