Skip to content
View gist:0a8143be68ee70ddb2c1
> cat build.sbt
name := "scalaz-wtf"
version := "1.0"
organization := "com.joshcough"
scalaVersion := "2.11.7"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.3"
View Server.scala
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
View gist:1e6225e753609b33f843
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)
View ChannelComposition.scala
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],
View gist:4f6958336a4df49cadfa
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
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]
Something went wrong with that request. Please try again.