Skip to content

Instantly share code, notes, and snippets.

View dbousamra's full-sized avatar

Dominic Bou-Samra dbousamra

  • Piccolo Health
  • Australia
View GitHub Profile
object Example {
def process(implicit strat: Strategy): Sink[Task, List[Int]] = { ms =>
ms.evalMap { i =>
Task {
println(s"In consumer length ${i.length}")
Thread.sleep(200)
}
}
}
object Example {
def main(args: Array[String]): Unit = {
implicit val strat = fs2.Strategy.fromCachedDaemonPool()
val ms: Stream[Task, String] = Stream.eval {
Task {
println("Evaluating message stream")
Thread.sleep(1000)
object Example {
def messageStream(client: AmazonSQSAsyncClient, request: ReceiveMessageRequest)(implicit s: Strategy): Stream[Task, Message] = {
Stream.repeatEval(AsyncSQS.getMessagesAsync(client, request)).flatMap { result =>
Stream.emits(result.getMessages.asScala)
}
}
def batchPipe(n: Int): Pipe[Task, Message, List[Message]] = { messages =>
messages.vectorChunkN(n, true).map(_.toList)
}
case class Gen[A](g: () => A) {
/*
* Evaluates a Gen, yielding a value
*/
def sample: A = {
g()
}
/*
import argonaut._
import Argonaut._
import argonaut.CursorOpDownArray
case class Job(name: String, salary: Option[Int])
case class Person(name: String, job: Job)
object Person {
var sumAsync = function(a, b, callback) {
sleep(1000)
return callback(a + b);
}
{
"name":"water",
"generation":{
"url":"http:\/\/pokeapi.co\/api\/v2\/generation\/1\/",
"name":"generation-i"
},
"damage_relations":{
"half_damage_from":[
{
"url":"http:\/\/pokeapi.co\/api\/v2\/type\/9\/",
object Example {
def main(args: Array[String]): Unit = {
val messages: Stream[fs2.Task, Int] = Stream.constant[fs2.Task, Int](1).repeat
val process: Pipe[fs2.Task, Int, String] = _.evalMap { m =>
FS2Helpers.task2fs2Task(scalaz.concurrent.Task.now(m.toString)) // now, oddly, if this is Task { ... } instead of now(..) it works fine
}
val pipeline = messages.through(process)
pipeline.run.unsafeRun()
}
}
object Metrics {
val MetricsPrefix = "http4s"
val StatusTagPrefix = "status"
val StatusInformation = 100
val StatusOk = 200
val StatusRedirection = 300
val StatusClientError = 400
val StatusServerError = 500