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
object LetLangError { | |
import scala.language.higherKinds | |
import scalaz.{Bind, Monad, \/} | |
import scalaz.syntax.either._ | |
import scalaz.syntax.monadError._ | |
import scalaz.syntax.applicative._ | |
// import scalaz.syntax.monad._ | |
import scalaz.MonadError |
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
object L3Z { | |
import scalaz.Writer | |
import scalaz.std.list._ | |
import scalaz.syntax.writer._ | |
import scalaz.syntax.applicative._ | |
import scalaz.syntax.foldable._ | |
trait Exp | |
case class Num (i:Int) extends Exp |
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
implicit class RichV[S[_]:Applicative,E,T](v:Validation[E, T]) | |
(implicit sg: Semigroup[S[E]]){ | |
def leftFlatMap[U](f: E => Validation[S[E],U]): Validation[S[E],T] = | |
v.leftMap{ e => f(e).fold(sg.append(e.point[S], _), _ => e.point[S]) } | |
} | |
implicit class RichNelV[S[_],E,T](v:Validation[S[E], T]) | |
(implicit sg: Semigroup[S[E]]){ | |
def leftFlatMap[U](f: S[E] => Validation[S[E],U]): Validation[S[E],T] = | |
v.leftMap{ es => f(es).fold(sg.append(_, es), _ => es) } |
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
> cat build.sbt | |
name := "scalaz-wtf" | |
version := "1.0" | |
organization := "com.joshcough" | |
scalaVersion := "2.11.7" | |
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.3" |
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
package processes | |
import scalaz.concurrent.Task | |
import scalaz.stream._ | |
object TestServer { | |
def main(args: Array[String]): Unit = { | |
val reader = Process((1 to 10):_*) | |
val resultSink: Sink[Task, Int] = sink lift { i => Task(println("i=" + i)) } | |
def writer(p: Process[Task, Int]): Process[Task, Unit] = p to resultSink |
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 scalaz.concurrent.{Future, Task} | |
import scalaz.stream._ | |
object TestServer { | |
def main(args: Array[String]): Unit = { | |
val reader = Process((1 to 10):_*) | |
val resultSink: Sink[Task, Int] = sink lift { i => Task(println("i=" + i)) } | |
def writer(p: Process[Task, Int]): Process[Task, Unit] = p to resultSink | |
// main loop | |
StreamingServer.serve(reader)(writer) |
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
object Procs { | |
implicit class RichProcess[F[_], A](p: Process[F, A]) { | |
def through2[B,C](c1: Channel[F, A, B], | |
c2: Channel[F, B, C]): Process[F, C] = | |
p.flatMap(composeChannels(c1, c2)) | |
} | |
implicit class RichTaskProcess[A](p: Process[Task, A]) { | |
def observeThrough2[B,C](c1: Channel[Task, A, B], |
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
Process(words:_*). | |
observe(printer). | |
through(kinesisChan). // this has to be fast, and i dont care about the rest | |
through(runFutures). // so all this stuff can be slow | |
map(_.toString). | |
observe(printer). | |
run.run |
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
module Foo where | |
import Debug.Trace | |
traceByteString :: String -> ByteString -> ByteString | |
traceByteString msg b | traceShow b False = undefined | |
traceByteString msg b = b |
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.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 |