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 OutputStreamUtils { | |
def outToSource(queueSize: Int)(f: OutputStream => Unit)(implicit S: Strategy): Process[Task, ByteVector] = { | |
val queue = async.boundedQueue[ByteVector](queueSize) | |
val qos = new QueueOutputStream(queue) | |
S(f(qos)) | |
queue.dequeue | |
} | |
} |
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 java.io.OutputStream | |
import scalaz.stream._ | |
import scodec.bits.ByteVector | |
class QueueOutputStream(q: async.mutable.Queue[ByteVector]) extends OutputStream { | |
override def write(b: Int): Unit = | |
q.enqueueOne(ByteVector(b & 0xff)).run |
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
case class Response(results: Seq[String], nextPage: Option[Int]) | |
def getPagedUrl(url: String, curPage: Option[Int]): Task[Response] = ??? | |
def pagedRequest(url: String, curPage: Option[Int] = None): Process[Task, String] = { | |
Process.eval(getPagedUrl(url, curPage)) flatMap { response => | |
Process.emitAll(response.results) ++ | |
response.nextPage.map(p => pagedRequest(url, Some(p))).getOrElse(Process.empty) | |
} | |
} |
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
implicit class Task2FutureWrapper[A](task: scalaz.concurrent.Task[A]) { | |
import scala.concurrent.{Future, Promise} | |
import scalaz.{-\/,\/-} | |
def runFuture(): Future[A] = { | |
val p = Promise[A]() | |
task.runAsync { | |
case -\/(t) => p.failure(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 org.scalatest._ | |
class AllSuites extends Suites( | |
new FailureSuite, | |
new SuccessSuite | |
) | |
class FailureSuite extends FlatSpec { | |
"1" should "equal 2" in { | |
assert(1 === 2) |
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
### Keybase proof | |
I hereby claim: | |
* I am fiadliel on github. | |
* I am fiadliel (https://keybase.io/fiadliel) on keybase. | |
* I have a public key whose fingerprint is BABC C4C8 109D 001F 81E4 A7DB 13BB D061 3BB9 93C4 | |
To claim this, I am signing this object: |
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 typeclass_example | |
case class Example(a: Int, b: String) |
NewerOlder