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 gotchas | |
object NoArgMethods { | |
val l = List(1, 2, 3) | |
val correct = l.toSet // has type Set[Int] | |
val wrong = l.toSet() // has type Boolean | |
// toSet() is converted to toSet.apply() |
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 dispatch.classic./\ | |
import dispatch.classic.mime.Mime.MimeRequestTerms | |
val multipart = new MimeRequestTerms(/\) <<*("counterparty-file", anyString(), bytes) | |
val byteStream = new ByteArrayOutputStream() | |
multipart.body.get.writeTo(byteStream) | |
Request(url, RequestMethods.POST, | |
Map(HttpHeaders.ContentType.value -> multipart.body.get.getContentType.getValue), | |
byteStream.toByteArray) |
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
/* | |
Thx to Albert Latacz for passing this on to me | |
Think its more or less a direct lift from the Artima Programming in Scala book, chapter 33 | |
at http://booksites.artima.com/programming_in_scala_2ed/examples/html/ch33.html | |
*/ | |
import java.io.InputStreamReader | |
import pure.commons.store.FileUtils | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input.StreamReader |
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 BuildInfo { | |
lazy val settings = sourceGenerators in Test <+= (streams, sourceManaged in Test, baseDirectory) map emitBuildInfo | |
def emitBuildInfo(logger: TaskStreams, outputDir: File, baseDir: File): Seq[File] = { | |
val outputFile = outputDir / "BuildInfo.scala" | |
logger.log.info(s"Generating build info file at: ${outputFile}") | |
IO.write(outputFile, | |
s""" |
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 Christopher Schmidt 2010 | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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 A | |
class A2 extends A | |
class B | |
trait M[X] | |
// | |
// Upper Type Bound | |
// | |
def upperTypeBound[AA <: A](x: AA): A = x |
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
/** GADTs in Scala and their limitations */ | |
/** Background: what is an algebraic data type (ADT) ? | |
* ADT: (possibly) recursive datatype with sums and products | |
* In scala - a trait with case classes (case class is product, subtyping is sum) | |
*/ | |
/** Motivation: untyped embedded DSL doesn't prevent nonsensical expressions */ | |
sealed trait Expr { | |
def apply(other: Expr) = Ap(this, other) |
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
// No case classes | |
object Consoles { | |
trait ConsoleAlg[F[_]] { | |
def readLine: F[Option[String]] | |
def printLine(line: String): F[Unit] | |
} | |
trait Console[+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
import scalaz.effect.IO | |
import scalaz.{EitherT, Monad} | |
object Program extends ProgramInstances { | |
def apply[A](a: A): Program[A] = Program[A](EitherT.right[IO, Throwable, A](IO(a))) | |
} | |
trait ProgramInstances { | |
implicit object ProgramMonad extends Monad[Program] { | |
override def point[A](a: => A): Program[A] = Program[A](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
package demo | |
import scalaz._ | |
import scalaz.syntax._ | |
import scalaz.effect.IO | |
import scalaz.effect.IO._ | |
import scalaz.syntax.std.either._ | |
object Demo { | |
type M[A] = EitherT[IO, Throwable, A] |
OlderNewer