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._, Scalaz._ | |
trait Baz extends Foo { | |
def r = List(1).liftM[T] | |
} |
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
package org.brianmckenna.wartremover | |
package warts | |
object Typecase extends WartTraverser { | |
def apply(u: WartUniverse): u.Traverser = { | |
import u.universe._ | |
val typedFinder = new Traverser { | |
override def traverse(tree: Tree) { | |
tree match { |
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._, Scalaz._, concurrent.{ Future, Task } | |
import argonaut._, Argonaut._ | |
object ArgonautDemo extends JsonDemo { | |
val entitySum = DecodeJson(c => | |
entityNames.traverseU(c.get[JsonArray](_).map(_.size)).map(_.sum) | |
) | |
val resultReads = DecodeJson(c => | |
c.get[Json]("delete").map(_ => Result.deletion) ||| ( |
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 shapeless._ | |
trait ZipWith[HF, AL <: HList, BL <: HList] extends DepFn2[AL, BL] { | |
type Out <: HList | |
} | |
object ZipWith { | |
def apply[HF, AL <: HList, BL <: HList](implicit | |
zw: ZipWith[HF, AL, BL] | |
): Aux[HF, AL, BL, zw.Out] = zw |
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._, Scalaz._, concurrent.Future | |
def slowInt(i: Int) = { Thread.sleep(200); i } | |
def slowAdd(x: Int, y: Int) = { Thread.sleep(100); x + y } | |
def futures = (1 to 20).map(i => Future(slowInt(i))) | |
def timeFuture[A](fn: => Future[A]) = { | |
val t0 = System.currentTimeMillis | |
val a = fn.run | |
println((System.currentTimeMillis - t0) / 1000.0 + "s") |
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
package argonaut | |
import argonaut._, Argonaut._ | |
import scala.language.experimental.macros | |
import scalaz._, Scalaz._ | |
import shapeless._ | |
object AutoCodecJson { | |
implicit def deriveEncodeJson[T] = macro GenericMacros.deriveProductInstance[EncodeJson, T] | |
implicit def deriveDecodeJson[T] = macro GenericMacros.deriveProductInstance[DecodeJson, T] |
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 scala.concurrent.{ ExecutionContext, Future } | |
import shapeless._, ops.tuple.{ IsComposite, LeftFolder, Prepend } | |
object zipAndAdd extends Poly2 { | |
implicit def only[B, A](implicit p: Prepend[B, Tuple1[A]], executor: ExecutionContext) = | |
at[Future[B], Future[A]] { | |
(fb, fa) => fb.zip(fa).map { case (b, a) => p(b, Tuple1(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
import scalaz._, Scalaz._ | |
def setS(i: Int): State[List[Int], Unit] = modify(i :: _) | |
val s = (1 to 10000).foldLeft(state[List[Int], Unit](()).lift[Free.Trampoline]) { | |
case (st, i) => st.flatMap(_ => setS(i).lift[Free.Trampoline]) | |
} | |
s(Nil) |
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) | |
import scala.language.dynamics | |
import scala.language.experimental.macros | |
import scala.reflect.macros.whitebox | |
object implicitly extends Dynamic { | |
def apply[T](implicit t: T): T {} = t |
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
sealed trait A { | |
type Typeclass[T] <: { def apply(): Unit } | |
} | |
case class B() extends A { | |
trait Typeclass[T] { def apply(): Unit } | |
object Typeclass { | |
implicit val intClass: Typeclass[Int] = new Typeclass[Int] { | |
def apply() { println("B.Int") } |
OlderNewer