Skip to content
View debug.hs
module Foo where
import Debug.Trace
traceByteString :: String -> ByteString -> ByteString
traceByteString msg b | traceShow b False = undefined
traceByteString msg b = b
View gist:2b0f07e6a3532266d3cc
scala> import scalaz.concurrent.Task
import scalaz.concurrent.Task
scala> def convert[A](str: => Stream[A]): Process[Task, Throwable \/ A] =
| Process.eval((Task delay str map {
| case hd #:: tail => emit(hd.right) ++ convert(tail)
| case Stream.Empty => halt
| }).attempt) flatMap {
| case lf@ -\/(_) => emit(lf)
| case \/-(p) => p
View gist:cfce120c60057a203275
def convert[A](str: => Stream[A]): Process[Task, Throwable \/ A] =
Process.eval((Task delay str map {
case hd #:: tail => emit(hd.right) ++ convert(tail)
case Stream.Empty => halt
}).attempt) flatMap {
case lf@ -\/(_) => emit(lf)
case \/-(p) => p
}
View gist:6e2b13a025121811748b
import scalaz.stream._
import scalaz.stream.Process._
object WriterProps {
def convert[A](str: Stream[A]): Process0[A] = str match {
case hd #:: tail => emit(hd) ++ convert(tail)
case _ => halt
}
def main (args: Array[String]): Unit = {
convert(Stream(0, 1) map { i =>
View gist:58e16ba26d4a6f3dde6e
trait Go[-I,O] { def go(i:I): O }
object Go {
def go[A, B](f: A => B) = new Go[A, B] {
def go(a: A) = f(a)
}
trait WhatMap[A, B] {
def whatMap[A1](f: A1 => A): Go[A1, B]
View gist:0e2e80a934bac1b8a9f9
object Process1Test {
val o: Process[IO, String] = null
val x: Process1[String, Int] = null
val y: Process[IO, Int] = o.pipe(x)
}
View gist:0beb2338da716ef2a406
import scalaz.Contravariant
trait Go[-I,O] { def go(i:I): O }
object Go {
implicit def GoContravariant[O]: Contravariant[Go[?,O]] =
new Contravariant[Go[?, O]] {
def contramap[A, B](r: Go[A, O])(f: B => A): Go[B, O] =
new Go[B, O] { def go(b: B): O = r go f(b) }
View gist:6ac517c6b972f004816a
def asyncTask(i: I)(implicit e: Executor): Task[O] = Task.suspend({
Task.async { (cb: (Throwable \/ O) => Unit) =>
Futures.addCallback(eval(i), new FutureCallback[O]() {
def onSuccess(result: O) = {
cb(result.right)
self.onSuccess(result)
}
def onFailure(t: Throwable) = {
cb(t.left)
self.onFailure(t)
View gist:b29a70be8c6d65da0fc8
import com.google.common.util.concurrent.{FutureCallback, Futures, MoreExecutors, ListenableFuture}
import java.util.concurrent.{Callable, Executors}
import scalaz.\/
import scalaz.concurrent.Task
import scalaz.stream._
import scalaz.syntax.either._
object TestWriter {
View gist:0e044525e1dc681a59e7
object ErrorNotifier {
implicit val ErrorNotifierMonoid = new scalaz.Monoid[ErrorNotifier]{
def zero: ErrorNotifier = NullNotifier
def append(f1: ErrorNotifier, f2: => ErrorNotifier): ErrorNotifier = (f1, f2) match {
case (NullNotifier, NullNotifier) => NullNotifier
case (NullNotifier, e) => e
case (e, NullNotifier) => e
case (e1, e2) => new CombinedNotifier(e1, e2)
}
}
Something went wrong with that request. Please try again.