This file contains 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._ | |
import Scalaz.{merge => _, _} | |
import scalaz.concurrent._ | |
import scalaz.stream._ | |
import scala.concurrent.duration._ | |
implicit val defaultScheduler = scalaz.stream.DefaultScheduler | |
val flag = async.signal[Boolean] | |
val reset = Process.eval(flag set true).drain |
This file contains 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 sbt._ | |
import Keys._ | |
object SinksBuild extends Build { | |
// Custom keys -- things don't work well if they are on .sbt files | |
lazy val scalazVersion = settingKey[String]("Scalaz Version") | |
lazy val scodecVersion = settingKey[String]("Scodec Version") | |
lazy val unfilteredVersion = settingKey[String]("Unfiltered Version") | |
lazy val scalacheckVersion = settingKey[String]("Scalacheck Version") | |
lazy val specs2Version = settingKey[String]("Specs2 Version") |
This file contains 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
// javassist is used by logback, optionally. Like logback, don't pollute upstream dependencies. | |
"ch.qos.logback" % "logback-classic" % "1.1.1" % "optional", |
This file contains 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 sbt.Keys._ | |
import sbt._ | |
import java.nio.file.Files | |
object TempDir extends AutoPlugin { | |
object autoImport { | |
lazy val tempDir = taskKey[File]("Sets target.temp.directory Java property. Creates the directory if needed.") | |
} | |
import autoImport._ |
This file contains 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
shellPrompt <<= name(name => { state: State => | |
object devnull extends ProcessLogger { | |
def info(s: => String) {} | |
def error(s: => String) { } | |
def buffer[T](f: => T): T = f | |
} | |
val current = """\*\s+(\w+)""".r | |
def gitBranches = ("git branch --no-color" lines_! devnull mkString) | |
"%s:%s>" format ( | |
name, |
This file contains 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
(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps)) | |
// Forward-pipe courtesy of Scalaz, or look here: http://stevegilham.blogspot.com/2009/01/pipe-operator-in-scala.html |
This file contains 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 iterationForCoin(stream: Stream[Int], coin: Int) = { | |
val (lower, higher) = stream splitAt coin | |
val next: Stream[Int] = lower #::: (higher zip next map { case (a, b) => a + b }) | |
next.toList | |
} | |
val coins = List(1, 2, 5, 10, 20, 50, 100, 200) | |
coins.foldLeft(1 #:: Stream.fill(200)(0))(iterationForCoin).last |
This file contains 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 DynamicImpl(x: AnyRef) extends Dynamic { | |
def _select_(name: String): DynamicImpl = { | |
new DynamicImpl(x.getClass.getMethod(name).invoke(x)) | |
} | |
def _invoke_(name: String)(args: Any*) = { | |
new DynamicImpl(x.getClass.getMethod(name, args.map(_.asInstanceOf[AnyRef].getClass) : _*).invoke(x, args.map(_.asInstanceOf[AnyRef]) : _*)) | |
} | |
def typed[T] = x.asInstanceOf[T] | |
override def toString = "Dynamic(" + x.toString + ")" | |
} |
This file contains 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[_] <: Seq[_]](f: A[Int]) = f.head | |
f: [A[_] <: Seq[_]](f: A[Int])A | |
scala> def f[A[_] <: Seq[t] forSome { type t }](f: A[Int]) = f.head | |
f: [A[_] <: Seq[_]](f: A[Int])A | |
scala> def f[A[t] <: Seq[_] forSome { type t}](f: A[Int]) = f.head | |
f: [A[t] <: Seq[_] forSome { type t }](f: A[Int])A |
This file contains 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> :paste | |
// Entering paste mode (ctrl-D to finish) | |
class T[+A, +B] | |
trait LowerPriorityImplicits { | |
case object No extends T[Nothing, Nothing] | |
implicit val im = No | |
} | |
object T extends LowerPriorityImplicits { | |
implicit def toT[A, B](implicit ev: A =:= B) = new T[A, B] |
OlderNewer