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 sbt._ | |
import Keys._ | |
import ProtobufPlugin._ | |
object build extends Build { | |
// ... the usual project setup stuff thingly | |
settings = Defaults.defaultSettings ++ protobufSettings ++ Seq( | |
scalaSource in protobufConfig <<= (sourceDirectory)(_ / "generated_scala") | |
) | |
} |
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
// see https://github.com/gseitz/Lensed | |
object Lensed { | |
import scalaz._ | |
import Scalaz._ | |
case class Address(street: String, number: Int) | |
case class Person(name: String, address: Address) |
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
➜ ~/.ivy2/cache/org.scalaz/scalaz-core_2.9.0-1/jars scala -cp scalaz-core_2.9.0-1-6.0.1.jar | |
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import scalaz._ | |
import scalaz._ | |
scala> |
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 akka.actor.Actor | |
import com.yammer.metrics.Instrumented | |
// Useful for monitoring the mailbox size of actors. | |
// Just fire up your favorite JMX client and watch the pretty graph (which hopefully is a flatline at 0). | |
trait ActorMetrics extends Instrumented { actor: Actor => | |
metrics.gauge("mailbox size", self.id){actor.self.dispatcher.mailboxSize(actor.self)} | |
} |
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
"FingerTree" should { | |
"apply effects in order" in { | |
import std.string._ | |
import Id._ | |
type StringWriter[A] = Writer[String, A] | |
val s: Writer[String, FingerTree[Int, Int]] = streamToTree(intStream.take(5)).traverseTree[StringWriter, Int, Int](x => Writer(x.toString, x)) | |
val (w, a) = s.runT | |
(w, a.toStream) must be_===("12345", streamToTree(intStream.take(5)).toStream) | |
} | |
} |
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 sbt._ | |
import Keys._ | |
//import com.github.siasia.WebPlugin | |
object BuildSettings { | |
// generic filter settings, need to be applied for Compile and Test | |
def wicketResourceSettings(config: Configuration) = inConfig(config)(Seq[Setting[_]]( | |
excludeFilter in unmanagedResources := ("*.java"), | |
unmanagedResourceDirectories <++= (unmanagedSourceDirectories) apply (identity) |
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> val pair = for { | |
| _ <- token(char('{')) | |
| id <- token(ident) | |
| _ <- token(char(':')) | |
| v <- integer | |
| _ <- token(char('}')) | |
| } yield id -> v | |
obj: scalaz.parse.huttonmeijer.Parser[(List[Char], Int)] = scalaz.parse.huttonmeijer.Parser$$anon$2@234e7730 | |
scala> pair("{ foo : 17 }".toList) |
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 PolyParse[F[_]] { | |
def F: Functor[F] | |
def APP: Applicative[F] | |
def ALT: Alternative[F] | |
def C: Commitment[F] | |
def M: MonadFail[F] | |
} | |
def oneOf[FA](fas: List[FA])(implicit U: Unapply[PolyParse, FA]): U.M[U.A] = fas match { | |
case Nil => U.TC.M.fail[U.A]("failed to parse any of the possible choices".toList) |
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 scalaz._ | |
import scalaz._ | |
scala> import Scalaz._ | |
import Scalaz._ | |
scala> Option(17) match { | |
| case opt @ Some(_) if opt /== Option(42) => | |
| } | |
<console>:48: error: type mismatch; |
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
// original, broken version | |
def many[A](a: F[A]): F[List[A]] = { | |
lazy val y: Free.Trampoline[F[List[A]]] = z map (plus(_, point(Nil))) | |
lazy val z: Free.Trampoline[F[List[A]]] = y map (map2(a, _)(_ :: _)) | |
y.run | |
} | |
// trying to make sense of trampoline |