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
// reifies the assertion that type A is an instance of typeclass F | |
final class instance[A, F[_]](value: A, typeclass: F[A]) { | |
def apply[B](f: (F[A], A) => B): B = f(typeclass, value) | |
} | |
// provides an implicit conversion from any A to the above "instance" wrapper | |
object instance { | |
implicit def anyToInstance[A, F[_]](a: A)(implicit fa: F[A]) = new instance(a, fa) | |
} |
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
object ScalazActorTest extends App { | |
import scalaz._ | |
import Scalaz._ | |
val running = new AtomicBoolean(false) | |
object Actor { | |
var count = 0 | |
def act() { | |
val b = running.get() |
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
object Util { | |
def BenchmarkCycles = 100000000 | |
def time[Z](label: String)(f: => Z): Z = { | |
val startTime = System.currentTimeMillis | |
val result = f | |
val endTime = System.currentTimeMillis |
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 lineToOffer(line: String, headers: List[String]) : Validation[NonEmptyList[String], Offer] = { | |
({commaSplit(_)} andThen {extractFields(_: List[String], headers)} apply line) :-> | |
{(v) => Offer(v._1, v._2, v._3, v._4)} | |
} | |
def commaSplit(l: String): String => List[String] = l.split(",").toList | |
def extractFields(x: List[String], headers: List[String]): Validation[NonEmptyList[String], (String, String, String, String)] = { | |
notEmpty(x(headers.indexOf("offer_name")), "No offer name specified on line:" + x.mkString(","))) <|***|> ( | |
notEmpty(x(headers.indexOf("email")), "No email specified on line:" + x.mkString(",")), |
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
/** | |
* A silly example using Kleisli composition of DB operations | |
* Based on an idea from Runar Bjarnason found here: | |
* https://groups.google.com/d/msg/scala-debate/xYlUlQAnkmE/FteqYKgo2zUJ | |
* | |
* Uses Scalaz7 | |
* | |
* @author <a href="mailto:[email protected]">Jim Powers</a> | |
*/ | |
object Monadic { |
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
/* | |
I want to use a higher-rank polymorphic function when transforming an AST to generalize the | |
'traversal' so it can be separated from the actual transformation of each node. | |
This snippet of code doesn't quite capture my use case but it provokes the same compile error | |
as I get here: https://gist.github.com/1139579 | |
*/ | |
trait ~>[F[_],G[_],C[_]] { | |
def apply[A](a: F[A])(implicit evidence: C[F[A]]): G[A] |